Tribe__Cache::get( string $id, string|array $expiration_trigger = '', mixed $default = false, int $expiration, mixed $args = array() )
Get cached data. Optionally set data if not previously set.
Contents
Note: When a default value or callback is specified, this value gets set in the cache.
Parameters
- $id
-
(string) (Required) The key for the cached value.
- $expiration_trigger
-
(string|array) (Optional) Hook to trigger cache invalidation.
Default value: ''
- $default
-
(mixed) (Optional) A default value or callback that returns a default value.
Default value: false
- $expiration
-
(int) (Optional) When the default value expires, if it gets set.
- $args
-
(mixed) (Optional) Args passed to callback.
Default value: array()
Return
(mixed)
Source
File: src/Tribe/Cache.php
public function get( $id, $expiration_trigger = '', $default = false, $expiration = 0, $args = array() ) {
$group = in_array( $id, $this->non_persistent_keys ) ? 'tribe-events-non-persistent' : 'tribe-events';
$value = wp_cache_get( $this->get_id( $id, $expiration_trigger ), $group );
// Value found.
if ( false !== $value ) {
return $value;
}
if ( is_callable( $default ) ) {
// A callback has been specified.
$value = call_user_func_array( $default, $args );
} else {
// Default is a value.
$value = $default;
}
// No need to set a cache value to false since non-existent values return false.
if ( false !== $value ) {
$this->set( $id, $value, $expiration, $expiration_trigger );
}
return $value;
}