Edit File by line
/home/zeestwma/ceyloniy.../wp-inclu.../SimplePi.../src/Cache
File: BaseDataCache.php
<?php
[0] Fix | Delete
[1] Fix | Delete
// SPDX-FileCopyrightText: 2004-2023 Ryan Parman, Sam Sneddon, Ryan McCue
[2] Fix | Delete
// SPDX-License-Identifier: BSD-3-Clause
[3] Fix | Delete
[4] Fix | Delete
declare(strict_types=1);
[5] Fix | Delete
[6] Fix | Delete
namespace SimplePie\Cache;
[7] Fix | Delete
[8] Fix | Delete
use InvalidArgumentException;
[9] Fix | Delete
[10] Fix | Delete
/**
[11] Fix | Delete
* Adapter for deprecated \SimplePie\Cache\Base implementations
[12] Fix | Delete
*
[13] Fix | Delete
* @internal
[14] Fix | Delete
*/
[15] Fix | Delete
final class BaseDataCache implements DataCache
[16] Fix | Delete
{
[17] Fix | Delete
/**
[18] Fix | Delete
* @var Base
[19] Fix | Delete
*/
[20] Fix | Delete
private $cache;
[21] Fix | Delete
[22] Fix | Delete
public function __construct(Base $cache)
[23] Fix | Delete
{
[24] Fix | Delete
$this->cache = $cache;
[25] Fix | Delete
}
[26] Fix | Delete
[27] Fix | Delete
/**
[28] Fix | Delete
* Fetches a value from the cache.
[29] Fix | Delete
*
[30] Fix | Delete
* Equivalent to \Psr\SimpleCache\CacheInterface::get()
[31] Fix | Delete
* <code>
[32] Fix | Delete
* public function get(string $key, mixed $default = null): mixed;
[33] Fix | Delete
* </code>
[34] Fix | Delete
*
[35] Fix | Delete
* @param string $key The unique key of this item in the cache.
[36] Fix | Delete
* @param mixed $default Default value to return if the key does not exist.
[37] Fix | Delete
*
[38] Fix | Delete
* @return array|mixed The value of the item from the cache, or $default in case of cache miss.
[39] Fix | Delete
*
[40] Fix | Delete
* @throws InvalidArgumentException
[41] Fix | Delete
* MUST be thrown if the $key string is not a legal value.
[42] Fix | Delete
*/
[43] Fix | Delete
public function get_data(string $key, $default = null)
[44] Fix | Delete
{
[45] Fix | Delete
$data = $this->cache->load();
[46] Fix | Delete
[47] Fix | Delete
if (!is_array($data)) {
[48] Fix | Delete
return $default;
[49] Fix | Delete
}
[50] Fix | Delete
[51] Fix | Delete
// ignore data if internal cache expiration time is not set
[52] Fix | Delete
if (!array_key_exists('__cache_expiration_time', $data)) {
[53] Fix | Delete
return $default;
[54] Fix | Delete
}
[55] Fix | Delete
[56] Fix | Delete
// ignore data if internal cache expiration time is expired
[57] Fix | Delete
if ($data['__cache_expiration_time'] < time()) {
[58] Fix | Delete
return $default;
[59] Fix | Delete
}
[60] Fix | Delete
[61] Fix | Delete
// remove internal cache expiration time
[62] Fix | Delete
unset($data['__cache_expiration_time']);
[63] Fix | Delete
[64] Fix | Delete
return $data;
[65] Fix | Delete
}
[66] Fix | Delete
[67] Fix | Delete
/**
[68] Fix | Delete
* Persists data in the cache, uniquely referenced by a key with an optional expiration TTL time.
[69] Fix | Delete
*
[70] Fix | Delete
* Equivalent to \Psr\SimpleCache\CacheInterface::set()
[71] Fix | Delete
* <code>
[72] Fix | Delete
* public function set(string $key, mixed $value, null|int|\DateInterval $ttl = null): bool;
[73] Fix | Delete
* </code>
[74] Fix | Delete
*
[75] Fix | Delete
* @param string $key The key of the item to store.
[76] Fix | Delete
* @param array<mixed> $value The value of the item to store, must be serializable.
[77] Fix | Delete
* @param null|int $ttl Optional. The TTL value of this item. If no value is sent and
[78] Fix | Delete
* the driver supports TTL then the library may set a default value
[79] Fix | Delete
* for it or let the driver take care of that.
[80] Fix | Delete
*
[81] Fix | Delete
* @return bool True on success and false on failure.
[82] Fix | Delete
*
[83] Fix | Delete
* @throws InvalidArgumentException
[84] Fix | Delete
* MUST be thrown if the $key string is not a legal value.
[85] Fix | Delete
*/
[86] Fix | Delete
public function set_data(string $key, array $value, ?int $ttl = null): bool
[87] Fix | Delete
{
[88] Fix | Delete
if ($ttl === null) {
[89] Fix | Delete
$ttl = 3600;
[90] Fix | Delete
}
[91] Fix | Delete
[92] Fix | Delete
// place internal cache expiration time
[93] Fix | Delete
$value['__cache_expiration_time'] = time() + $ttl;
[94] Fix | Delete
[95] Fix | Delete
return $this->cache->save($value);
[96] Fix | Delete
}
[97] Fix | Delete
[98] Fix | Delete
/**
[99] Fix | Delete
* Delete an item from the cache by its unique key.
[100] Fix | Delete
*
[101] Fix | Delete
* Equivalent to \Psr\SimpleCache\CacheInterface::delete()
[102] Fix | Delete
* <code>
[103] Fix | Delete
* public function delete(string $key): bool;
[104] Fix | Delete
* </code>
[105] Fix | Delete
*
[106] Fix | Delete
* @param string $key The unique cache key of the item to delete.
[107] Fix | Delete
*
[108] Fix | Delete
* @return bool True if the item was successfully removed. False if there was an error.
[109] Fix | Delete
*
[110] Fix | Delete
* @throws InvalidArgumentException
[111] Fix | Delete
* MUST be thrown if the $key string is not a legal value.
[112] Fix | Delete
*/
[113] Fix | Delete
public function delete_data(string $key): bool
[114] Fix | Delete
{
[115] Fix | Delete
return $this->cache->unlink();
[116] Fix | Delete
}
[117] Fix | Delete
}
[118] Fix | Delete
[119] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function