[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/ -> class-wp-feed-cache-transient.php (source)

   1  <?php
   2  /**
   3   * Feed API: WP_Feed_Cache_Transient class
   4   *
   5   * @package WordPress
   6   * @subpackage Feed
   7   * @since 4.7.0
   8   */
   9  
  10  /**
  11   * Core class used to implement feed cache transients.
  12   *
  13   * @since 2.8.0
  14   */
  15  #[AllowDynamicProperties]
  16  class WP_Feed_Cache_Transient {
  17  
  18      /**
  19       * Holds the transient name.
  20       *
  21       * @since 2.8.0
  22       * @var string
  23       */
  24      public $name;
  25  
  26      /**
  27       * Holds the transient mod name.
  28       *
  29       * @since 2.8.0
  30       * @var string
  31       */
  32      public $mod_name;
  33  
  34      /**
  35       * Holds the cache duration in seconds.
  36       *
  37       * Defaults to 43200 seconds (12 hours).
  38       *
  39       * @since 2.8.0
  40       * @var int
  41       */
  42      public $lifetime = 43200;
  43  
  44      /**
  45       * Constructor.
  46       *
  47       * @since 2.8.0
  48       * @since 3.2.0 Updated to use a PHP5 constructor.
  49       *
  50       * @param string $location  URL location (scheme is used to determine handler).
  51       * @param string $filename  Unique identifier for cache object.
  52       * @param string $extension 'spi' or 'spc'.
  53       */
  54  	public function __construct( $location, $filename, $extension ) {
  55          $this->name     = 'feed_' . $filename;
  56          $this->mod_name = 'feed_mod_' . $filename;
  57  
  58          $lifetime = $this->lifetime;
  59          /**
  60           * Filters the transient lifetime of the feed cache.
  61           *
  62           * @since 2.8.0
  63           *
  64           * @param int    $lifetime Cache duration in seconds. Default is 43200 seconds (12 hours).
  65           * @param string $filename Unique identifier for the cache object.
  66           */
  67          $this->lifetime = apply_filters( 'wp_feed_cache_transient_lifetime', $lifetime, $filename );
  68      }
  69  
  70      /**
  71       * Sets the transient.
  72       *
  73       * @since 2.8.0
  74       *
  75       * @param SimplePie $data Data to save.
  76       * @return true Always true.
  77       */
  78  	public function save( $data ) {
  79          if ( $data instanceof SimplePie ) {
  80              $data = $data->data;
  81          }
  82  
  83          set_transient( $this->name, $data, $this->lifetime );
  84          set_transient( $this->mod_name, time(), $this->lifetime );
  85          return true;
  86      }
  87  
  88      /**
  89       * Gets the transient.
  90       *
  91       * @since 2.8.0
  92       *
  93       * @return mixed Transient value.
  94       */
  95  	public function load() {
  96          return get_transient( $this->name );
  97      }
  98  
  99      /**
 100       * Gets mod transient.
 101       *
 102       * @since 2.8.0
 103       *
 104       * @return mixed Transient value.
 105       */
 106  	public function mtime() {
 107          return get_transient( $this->mod_name );
 108      }
 109  
 110      /**
 111       * Sets mod transient.
 112       *
 113       * @since 2.8.0
 114       *
 115       * @return bool False if value was not set and true if value was set.
 116       */
 117  	public function touch() {
 118          return set_transient( $this->mod_name, time(), $this->lifetime );
 119      }
 120  
 121      /**
 122       * Deletes transients.
 123       *
 124       * @since 2.8.0
 125       *
 126       * @return true Always true.
 127       */
 128  	public function unlink() {
 129          delete_transient( $this->name );
 130          delete_transient( $this->mod_name );
 131          return true;
 132      }
 133  }


Generated : Sat Apr 20 08:20:01 2024 Cross-referenced by PHPXref