wppaste
WordPress

BaseDataCache

Source
wp-includes/SimplePie/src/Cache/BaseDataCache.php:17
Adapter for deprecated \SimplePie\Cache\Base implementations

Compatibility

WordPress
core
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0).

Properties · 1

$cacheSimplePie\Cache\Baseprivate

Methods · 4

Source code

final class BaseDataCache implements DataCache{    /**     * @var Base     */    private $cache;     public function __construct(Base $cache)    {        $this->cache = $cache;    }     /**     * Fetches a value from the cache.     *     * Equivalent to \Psr\SimpleCache\CacheInterface::get()     * <code>     * public function get(string $key, mixed $default = null): mixed;     * </code>     *     * @param string $key     The unique key of this item in the cache.     * @param mixed  $default Default value to return if the key does not exist.     *     * @return array|mixed The value of the item from the cache, or $default in case of cache miss.     *     * @throws InvalidArgumentException     *   MUST be thrown if the $key string is not a legal value.     */    public function get_data(string $key, $default = null)    {        $data = $this->cache->load();         if (!is_array($data)) {            return $default;        }         // ignore data if internal cache expiration time is not set        if (!array_key_exists('__cache_expiration_time', $data)) {            return $default;        }         // ignore data if internal cache expiration time is expired        if ($data['__cache_expiration_time'] < time()) {            return $default;        }         // remove internal cache expiration time        unset($data['__cache_expiration_time']);         return $data;    }     /**     * Persists data in the cache, uniquely referenced by a key with an optional expiration TTL time.     *     * Equivalent to \Psr\SimpleCache\CacheInterface::set()     * <code>     * public function set(string $key, mixed $value, null|int|\DateInterval $ttl = null): bool;     * </code>     *     * @param string   $key   The key of the item to store.     * @param array<mixed> $value The value of the item to store, must be serializable.     * @param null|int $ttl   Optional. The TTL value of this item. If no value is sent and     *                                      the driver supports TTL then the library may set a default value     *                                      for it or let the driver take care of that.     *     * @return bool True on success and false on failure.     *     * @throws InvalidArgumentException     *   MUST be thrown if the $key string is not a legal value.     */    public function set_data(string $key, array $value, ?int $ttl = null): bool    {        if ($ttl === null) {            $ttl = 3600;        }         // place internal cache expiration time        $value['__cache_expiration_time'] = time() + $ttl;

Changelog

Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/SimplePie/src/Cache/BaseDataCache.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.