3 * Feed API: WP_Feed_Cache_Transient class
11 * Core class used to implement feed cache transients.
15 class WP_Feed_Cache_Transient {
18 * Holds the transient name.
27 * Holds the transient mod name.
36 * Holds the cache duration in seconds.
38 * Defaults to 43200 seconds (12 hours).
44 public $lifetime = 43200;
50 * @since 3.2.0 Updated to use a PHP5 constructor.
53 * @param string $location URL location (scheme is used to determine handler).
54 * @param string $filename Unique identifier for cache object.
55 * @param string $extension 'spi' or 'spc'.
57 public function __construct($location, $filename, $extension) {
58 $this->name = 'feed_' . $filename;
59 $this->mod_name = 'feed_mod_' . $filename;
61 $lifetime = $this->lifetime;
63 * Filters the transient lifetime of the feed cache.
67 * @param int $lifetime Cache duration in seconds. Default is 43200 seconds (12 hours).
68 * @param string $filename Unique identifier for the cache object.
70 $this->lifetime = apply_filters( 'wp_feed_cache_transient_lifetime', $lifetime, $filename);
79 * @param SimplePie $data Data to save.
80 * @return true Always true.
82 public function save($data) {
83 if ( $data instanceof SimplePie ) {
87 set_transient($this->name, $data, $this->lifetime);
88 set_transient($this->mod_name, time(), $this->lifetime);
98 * @return mixed Transient value.
100 public function load() {
101 return get_transient($this->name);
105 * Gets mod transient.
110 * @return mixed Transient value.
112 public function mtime() {
113 return get_transient($this->mod_name);
117 * Sets mod transient.
122 * @return bool False if value was not set and true if value was set.
124 public function touch() {
125 return set_transient($this->mod_name, time(), $this->lifetime);
129 * Deletes transients.
134 * @return true Always true.
136 public function unlink() {
137 delete_transient($this->name);
138 delete_transient($this->mod_name);