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 4.6.1.1 6.5.1.4 4.6.10 6.5.1.5 4.6.10.2 6.5.1.6 4.6.11 6.5.2 4.6.11.2 6.6.0 4.6.12.1 6.6.0.1 4.6.13.1 6.6.0.2 4.6.14 6.6.1 4.6.14.2 6.6.2 4.6.15.1 6.6.3 4.6.16.1 6.6.4 4.6.17.1 6.6.4.1 4.6.18.1 6.6.4.2 4.6.19.1 6.7.0 4.6.2.1 6.7.1 4.6.20 6.8.0 4.6.20.2 6.8.1 4.6.21.1 6.8.2 4.6.22 6.8.2.1 4.6.22.2 6.8.3 4.6.23.1 6.9.0 4.6.24 6.9.1 4.6.24.2 4.6.25.1 4.6.26 4.6.26.2 4.6.3.1 4.6.4.1 4.6.5.1 4.6.6.1 4.6.7.1 4.6.8.1 4.6.9.1 4.7 4.7.0.2 4.7.1.1 4.7.2.1 4.7.3.1 4.7.4.1 4.8 4.8.0.2 4.8.1.1 4.8.2.1 4.9.0.1 4.9.0.2 4.9.0.4 4.9.1 4.9.1.2 4.9.10.1 4.9.11.1 4.9.12.1 4.9.13.1 4.9.14.1 4.9.2.1 4.9.3 4.9.3.1 4.9.3.3 4.9.4.1 4.9.5.1 4.9.6.1 4.9.7.1 4.9.8.1 4.9.9.1 5.0.0 5.0.0.1 5.0.0.3 5.0.1.1 5.0.1.2 5.0.2 5.0.2.2 5.0.2.3 5.0.3 5.0.3.2 5.0.3.3 5.1.0.1 5.1.0.2
the-events-calendar / common / src / Tribe / Cache.php
the-events-calendar / common / src / Tribe Last commit date
Admin 8 years ago Ajax 8 years ago Asset 8 years ago Customizer 8 years ago Documentation 8 years ago Duplicate 8 years ago Image 8 years ago JSON_LD 8 years ago Languages 8 years ago Log 8 years ago Meta 8 years ago PUE 8 years ago Process 8 years ago REST 8 years ago Service_Providers 8 years ago Support 8 years ago Tabbed_View 8 years ago Utils 8 years ago Validator 8 years ago Abstract_Deactivation.php 8 years ago App_Shop.php 8 years ago Assets.php 8 years ago Assets_Pipeline.php 8 years ago Autoloader.php 8 years ago Cache.php 8 years ago Cache_Listener.php 8 years ago Changelog_Reader.php 8 years ago Container.php 8 years ago Context.php 8 years ago Cost_Utils.php 8 years ago Credits.php 8 years ago Customizer.php 8 years ago Data.php 8 years ago Date_Utils.php 8 years ago Debug.php 8 years ago Dependency.php 8 years ago Deprecation.php 8 years ago Error.php 8 years ago Exception.php 8 years ago Extension.php 8 years ago Extension_Loader.php 8 years ago Field.php 8 years ago Field_Conditional.php 8 years ago Log.php 8 years ago Main.php 8 years ago Notices.php 8 years ago Plugin_Meta_Links.php 8 years ago Plugins.php 8 years ago Plugins_API.php 8 years ago Post_History.php 8 years ago Post_Transient.php 8 years ago Rewrite.php 8 years ago Settings.php 8 years ago Settings_Manager.php 8 years ago Settings_Tab.php 8 years ago Simple_Table.php 8 years ago Support.php 8 years ago Tabbed_View.php 8 years ago Template.php 8 years ago Template_Factory.php 8 years ago Template_Part_Cache.php 8 years ago Templates.php 8 years ago Terms.php 8 years ago Timezones.php 8 years ago Tracker.php 8 years ago Validate.php 8 years ago View_Helpers.php 8 years ago
Cache.php
253 lines
1 <?php
2
3 /**
4 * Manage setting and expiring cached data
5 *
6 * Select actions can be used to force cached
7 * data to expire. Implemented so far:
8 * - save_post
9 *
10 * When used in its ArrayAccess API the cache will provide non persistent storage.
11 */
12 class Tribe__Cache implements ArrayAccess {
13 const NO_EXPIRATION = 0;
14 const NON_PERSISTENT = - 1;
15
16 /**
17 * @var array
18 */
19 protected $non_persistent_keys = array();
20
21 public static function setup() {
22 wp_cache_add_non_persistent_groups( array( 'tribe-events-non-persistent' ) );
23 }
24
25 /**
26 * @param string $id
27 * @param mixed $value
28 * @param int $expiration
29 * @param string $expiration_trigger
30 *
31 * @return bool
32 */
33 public function set( $id, $value, $expiration = 0, $expiration_trigger = '' ) {
34 $key = $this->get_id( $id, $expiration_trigger );
35
36 if ( $expiration == self::NON_PERSISTENT ) {
37 $group = 'tribe-events-non-persistent';
38 $this->non_persistent_keys[] = $key;
39 $expiration = 1;
40 } else {
41 $group = 'tribe-events';
42 }
43
44 return wp_cache_set( $key, $value, $group, $expiration );
45 }
46
47 /**
48 * @param $id
49 * @param $value
50 * @param int $expiration
51 * @param string $expiration_trigger
52 *
53 * @return bool
54 */
55 public function set_transient( $id, $value, $expiration = 0, $expiration_trigger = '' ) {
56 return set_transient( $this->get_id( $id, $expiration_trigger ), $value, $expiration );
57 }
58
59 /**
60 * Get cached data. Optionally set data if not previously set.
61 *
62 * Note: When a default value or callback is specified, this value gets set in the cache.
63 *
64 * @param string $id The key for the cached value.
65 * @param string $expiration_trigger Optional. Hook to trigger cache invalidation.
66 * @param mixed $default Optional. A default value or callback that returns a default value.
67 * @param int $expiration Optional. When the default value expires, if it gets set.
68 * @param mixed $args Optional. Args passed to callback.
69 *
70 * @return mixed
71 */
72 public function get( $id, $expiration_trigger = '', $default = false, $expiration = 0, $args = array() ) {
73 $group = in_array( $id, $this->non_persistent_keys ) ? 'tribe-events-non-persistent' : 'tribe-events';
74 $value = wp_cache_get( $this->get_id( $id, $expiration_trigger ), $group );
75
76 // Value found.
77 if ( false !== $value ) {
78 return $value;
79 }
80
81 if ( is_callable( $default ) ) {
82 // A callback has been specified.
83 $value = call_user_func_array( $default, $args );
84 } else {
85 // Default is a value.
86 $value = $default;
87 }
88
89 // No need to set a cache value to false since non-existent values return false.
90 if ( false !== $value ) {
91 $this->set( $id, $value, $expiration, $expiration_trigger );
92 }
93
94 return $value;
95 }
96
97 /**
98 * @param string $id
99 * @param string $expiration_trigger
100 *
101 * @return mixed
102 */
103 public function get_transient( $id, $expiration_trigger = '' ) {
104 return get_transient( $this->get_id( $id, $expiration_trigger ) );
105 }
106
107 /**
108 * @param string $id
109 * @param string $expiration_trigger
110 *
111 * @return bool
112 */
113 public function delete( $id, $expiration_trigger = '' ) {
114 return wp_cache_delete( $this->get_id( $id, $expiration_trigger ), 'tribe-events' );
115 }
116
117 /**
118 * @param string $id
119 * @param string $expiration_trigger
120 *
121 * @return bool
122 */
123 public function delete_transient( $id, $expiration_trigger = '' ) {
124 return delete_transient( $this->get_id( $id, $expiration_trigger ) );
125 }
126
127 /**
128 * @param string $key
129 * @param string $expiration_trigger
130 *
131 * @return string
132 */
133 public function get_id( $key, $expiration_trigger = '' ) {
134 $last = empty( $expiration_trigger ) ? '' : $this->get_last_occurrence( $expiration_trigger );
135 $id = $key . $last;
136 if ( strlen( $id ) > 40 ) {
137 $id = md5( $id );
138 }
139
140 return $id;
141 }
142
143 /**
144 * @param string $action
145 *
146 * @return int
147 */
148 public function get_last_occurrence( $action ) {
149 return (int) get_option( 'tribe_last_' . $action, time() );
150 }
151
152 /**
153 * @param string $action
154 * @param int $timestamp
155 */
156 public function set_last_occurrence( $action, $timestamp = 0 ) {
157 if ( empty( $timestamp ) ) {
158 $timestamp = time();
159 }
160 update_option( 'tribe_last_' . $action, (int) $timestamp );
161 }
162
163 /**
164 * Builds a key from an array of components and an optional prefix.
165 *
166 * @param mixed $components Either a single component of the key or an array of key components.
167 * @param string $prefix
168 * @param bool $sort Whether component arrays should be sorted or not to generate the key; defaults to `true`.
169 *
170 * @return string The resulting key.
171 */
172 public function make_key( $components, $prefix = '', $sort = true ) {
173 $key = '';
174 $components = is_array( $components ) ? $components : array( $components );
175 foreach ( $components as $component ) {
176 if ( $sort && is_array( $component ) ) {
177 $is_associative = count( array_filter( array_keys( $component ), 'is_numeric' ) ) < count( array_keys( $component ) );
178 if ( $is_associative ) {
179 ksort( $component );
180 } else {
181 sort( $component );
182 }
183 }
184 $key .= maybe_serialize( $component );
185 }
186
187 return $this->get_id( $prefix . md5( $key ) );
188 }
189
190 /**
191 * Whether a offset exists
192 *
193 * @link http://php.net/manual/en/arrayaccess.offsetexists.php
194 * @param mixed $offset <p>
195 * An offset to check for.
196 * </p>
197 * @return boolean true on success or false on failure.
198 * </p>
199 * <p>
200 * The return value will be casted to boolean if non-boolean was returned.
201 * @since 5.0.0
202 */
203 public function offsetExists( $offset ) {
204 return in_array( $offset, $this->non_persistent_keys );
205 }
206
207 /**
208 * Offset to retrieve
209 *
210 * @link http://php.net/manual/en/arrayaccess.offsetget.php
211 * @param mixed $offset <p>
212 * The offset to retrieve.
213 * </p>
214 * @return mixed Can return all value types.
215 * @since 5.0.0
216 */
217 public function offsetGet( $offset ) {
218 return $this->get( $offset );
219 }
220
221 /**
222 * Offset to set
223 *
224 * @link http://php.net/manual/en/arrayaccess.offsetset.php
225 * @param mixed $offset <p>
226 * The offset to assign the value to.
227 * </p>
228 * @param mixed $value <p>
229 * The value to set.
230 * </p>
231 * @return void
232 * @since 5.0.0
233 */
234 public function offsetSet( $offset, $value ) {
235 $this->set( $offset, $value, self::NON_PERSISTENT );
236 }
237
238 /**
239 * Offset to unset
240 *
241 * @link http://php.net/manual/en/arrayaccess.offsetunset.php
242 * @param mixed $offset <p>
243 * The offset to unset.
244 * </p>
245 * @return void
246 * @since 5.0.0
247 */
248 public function offsetUnset( $offset ) {
249 $this->delete( $offset );
250 }
251 }
252
253