48 * |
48 * |
49 * @param string $location URL location (scheme is used to determine handler). |
49 * @param string $location URL location (scheme is used to determine handler). |
50 * @param string $filename Unique identifier for cache object. |
50 * @param string $filename Unique identifier for cache object. |
51 * @param string $extension 'spi' or 'spc'. |
51 * @param string $extension 'spi' or 'spc'. |
52 */ |
52 */ |
53 public function __construct($location, $filename, $extension) { |
53 public function __construct( $location, $filename, $extension ) { |
54 $this->name = 'feed_' . $filename; |
54 $this->name = 'feed_' . $filename; |
55 $this->mod_name = 'feed_mod_' . $filename; |
55 $this->mod_name = 'feed_mod_' . $filename; |
56 |
56 |
57 $lifetime = $this->lifetime; |
57 $lifetime = $this->lifetime; |
58 /** |
58 /** |
59 * Filters the transient lifetime of the feed cache. |
59 * Filters the transient lifetime of the feed cache. |
61 * @since 2.8.0 |
61 * @since 2.8.0 |
62 * |
62 * |
63 * @param int $lifetime Cache duration in seconds. Default is 43200 seconds (12 hours). |
63 * @param int $lifetime Cache duration in seconds. Default is 43200 seconds (12 hours). |
64 * @param string $filename Unique identifier for the cache object. |
64 * @param string $filename Unique identifier for the cache object. |
65 */ |
65 */ |
66 $this->lifetime = apply_filters( 'wp_feed_cache_transient_lifetime', $lifetime, $filename); |
66 $this->lifetime = apply_filters( 'wp_feed_cache_transient_lifetime', $lifetime, $filename ); |
67 } |
67 } |
68 |
68 |
69 /** |
69 /** |
70 * Sets the transient. |
70 * Sets the transient. |
71 * |
71 * |
72 * @since 2.8.0 |
72 * @since 2.8.0 |
73 * |
73 * |
74 * @param SimplePie $data Data to save. |
74 * @param SimplePie $data Data to save. |
75 * @return true Always true. |
75 * @return true Always true. |
76 */ |
76 */ |
77 public function save($data) { |
77 public function save( $data ) { |
78 if ( $data instanceof SimplePie ) { |
78 if ( $data instanceof SimplePie ) { |
79 $data = $data->data; |
79 $data = $data->data; |
80 } |
80 } |
81 |
81 |
82 set_transient($this->name, $data, $this->lifetime); |
82 set_transient( $this->name, $data, $this->lifetime ); |
83 set_transient($this->mod_name, time(), $this->lifetime); |
83 set_transient( $this->mod_name, time(), $this->lifetime ); |
84 return true; |
84 return true; |
85 } |
85 } |
86 |
86 |
87 /** |
87 /** |
88 * Gets the transient. |
88 * Gets the transient. |
90 * @since 2.8.0 |
90 * @since 2.8.0 |
91 * |
91 * |
92 * @return mixed Transient value. |
92 * @return mixed Transient value. |
93 */ |
93 */ |
94 public function load() { |
94 public function load() { |
95 return get_transient($this->name); |
95 return get_transient( $this->name ); |
96 } |
96 } |
97 |
97 |
98 /** |
98 /** |
99 * Gets mod transient. |
99 * Gets mod transient. |
100 * |
100 * |
101 * @since 2.8.0 |
101 * @since 2.8.0 |
102 * |
102 * |
103 * @return mixed Transient value. |
103 * @return mixed Transient value. |
104 */ |
104 */ |
105 public function mtime() { |
105 public function mtime() { |
106 return get_transient($this->mod_name); |
106 return get_transient( $this->mod_name ); |
107 } |
107 } |
108 |
108 |
109 /** |
109 /** |
110 * Sets mod transient. |
110 * Sets mod transient. |
111 * |
111 * |
112 * @since 2.8.0 |
112 * @since 2.8.0 |
113 * |
113 * |
114 * @return bool False if value was not set and true if value was set. |
114 * @return bool False if value was not set and true if value was set. |
115 */ |
115 */ |
116 public function touch() { |
116 public function touch() { |
117 return set_transient($this->mod_name, time(), $this->lifetime); |
117 return set_transient( $this->mod_name, time(), $this->lifetime ); |
118 } |
118 } |
119 |
119 |
120 /** |
120 /** |
121 * Deletes transients. |
121 * Deletes transients. |
122 * |
122 * |
123 * @since 2.8.0 |
123 * @since 2.8.0 |
124 * |
124 * |
125 * @return true Always true. |
125 * @return true Always true. |
126 */ |
126 */ |
127 public function unlink() { |
127 public function unlink() { |
128 delete_transient($this->name); |
128 delete_transient( $this->name ); |
129 delete_transient($this->mod_name); |
129 delete_transient( $this->mod_name ); |
130 return true; |
130 return true; |
131 } |
131 } |
132 } |
132 } |