Edit File by line
/home/zeestwma/richards.../wp-inclu.../SimplePi.../src/Cache
File: BaseDataCache.php
<?php
[0] Fix | Delete
[1] Fix | Delete
/**
[2] Fix | Delete
* SimplePie
[3] Fix | Delete
*
[4] Fix | Delete
* A PHP-Based RSS and Atom Feed Framework.
[5] Fix | Delete
* Takes the hard work out of managing a complete RSS/Atom solution.
[6] Fix | Delete
*
[7] Fix | Delete
* Copyright (c) 2004-2022, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors
[8] Fix | Delete
* All rights reserved.
[9] Fix | Delete
*
[10] Fix | Delete
* Redistribution and use in source and binary forms, with or without modification, are
[11] Fix | Delete
* permitted provided that the following conditions are met:
[12] Fix | Delete
*
[13] Fix | Delete
* * Redistributions of source code must retain the above copyright notice, this list of
[14] Fix | Delete
* conditions and the following disclaimer.
[15] Fix | Delete
*
[16] Fix | Delete
* * Redistributions in binary form must reproduce the above copyright notice, this list
[17] Fix | Delete
* of conditions and the following disclaimer in the documentation and/or other materials
[18] Fix | Delete
* provided with the distribution.
[19] Fix | Delete
*
[20] Fix | Delete
* * Neither the name of the SimplePie Team nor the names of its contributors may be used
[21] Fix | Delete
* to endorse or promote products derived from this software without specific prior
[22] Fix | Delete
* written permission.
[23] Fix | Delete
*
[24] Fix | Delete
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
[25] Fix | Delete
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
[26] Fix | Delete
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
[27] Fix | Delete
* AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
[28] Fix | Delete
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
[29] Fix | Delete
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
[30] Fix | Delete
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
[31] Fix | Delete
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
[32] Fix | Delete
* POSSIBILITY OF SUCH DAMAGE.
[33] Fix | Delete
*
[34] Fix | Delete
* @package SimplePie
[35] Fix | Delete
* @copyright 2004-2022 Ryan Parman, Sam Sneddon, Ryan McCue
[36] Fix | Delete
* @author Ryan Parman
[37] Fix | Delete
* @author Sam Sneddon
[38] Fix | Delete
* @author Ryan McCue
[39] Fix | Delete
* @link http://simplepie.org/ SimplePie
[40] Fix | Delete
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
[41] Fix | Delete
*/
[42] Fix | Delete
[43] Fix | Delete
namespace SimplePie\Cache;
[44] Fix | Delete
[45] Fix | Delete
use InvalidArgumentException;
[46] Fix | Delete
[47] Fix | Delete
/**
[48] Fix | Delete
* Adapter for deprecated \SimplePie\Cache\Base implementations
[49] Fix | Delete
*
[50] Fix | Delete
* @package SimplePie
[51] Fix | Delete
* @subpackage Caching
[52] Fix | Delete
* @internal
[53] Fix | Delete
*/
[54] Fix | Delete
final class BaseDataCache implements DataCache
[55] Fix | Delete
{
[56] Fix | Delete
/**
[57] Fix | Delete
* @var Base
[58] Fix | Delete
*/
[59] Fix | Delete
private $cache;
[60] Fix | Delete
[61] Fix | Delete
public function __construct(Base $cache)
[62] Fix | Delete
{
[63] Fix | Delete
$this->cache = $cache;
[64] Fix | Delete
}
[65] Fix | Delete
[66] Fix | Delete
/**
[67] Fix | Delete
* Fetches a value from the cache.
[68] Fix | Delete
*
[69] Fix | Delete
* Equivalent to \Psr\SimpleCache\CacheInterface::get()
[70] Fix | Delete
* <code>
[71] Fix | Delete
* public function get(string $key, mixed $default = null): mixed;
[72] Fix | Delete
* </code>
[73] Fix | Delete
*
[74] Fix | Delete
* @param string $key The unique key of this item in the cache.
[75] Fix | Delete
* @param mixed $default Default value to return if the key does not exist.
[76] Fix | Delete
*
[77] Fix | Delete
* @return array|mixed The value of the item from the cache, or $default in case of cache miss.
[78] Fix | Delete
*
[79] Fix | Delete
* @throws InvalidArgumentException
[80] Fix | Delete
* MUST be thrown if the $key string is not a legal value.
[81] Fix | Delete
*/
[82] Fix | Delete
public function get_data(string $key, $default = null)
[83] Fix | Delete
{
[84] Fix | Delete
$data = $this->cache->load();
[85] Fix | Delete
[86] Fix | Delete
if (!is_array($data)) {
[87] Fix | Delete
return $default;
[88] Fix | Delete
}
[89] Fix | Delete
[90] Fix | Delete
// ignore data if internal cache expiration time is not set
[91] Fix | Delete
if (!array_key_exists('__cache_expiration_time', $data)) {
[92] Fix | Delete
return $default;
[93] Fix | Delete
}
[94] Fix | Delete
[95] Fix | Delete
// ignore data if internal cache expiration time is expired
[96] Fix | Delete
if ($data['__cache_expiration_time'] < time()) {
[97] Fix | Delete
return $default;
[98] Fix | Delete
}
[99] Fix | Delete
[100] Fix | Delete
// remove internal cache expiration time
[101] Fix | Delete
unset($data['__cache_expiration_time']);
[102] Fix | Delete
[103] Fix | Delete
return $data;
[104] Fix | Delete
}
[105] Fix | Delete
[106] Fix | Delete
/**
[107] Fix | Delete
* Persists data in the cache, uniquely referenced by a key with an optional expiration TTL time.
[108] Fix | Delete
*
[109] Fix | Delete
* Equivalent to \Psr\SimpleCache\CacheInterface::set()
[110] Fix | Delete
* <code>
[111] Fix | Delete
* public function set(string $key, mixed $value, null|int|\DateInterval $ttl = null): bool;
[112] Fix | Delete
* </code>
[113] Fix | Delete
*
[114] Fix | Delete
* @param string $key The key of the item to store.
[115] Fix | Delete
* @param array $value The value of the item to store, must be serializable.
[116] Fix | Delete
* @param null|int $ttl Optional. The TTL value of this item. If no value is sent and
[117] Fix | Delete
* the driver supports TTL then the library may set a default value
[118] Fix | Delete
* for it or let the driver take care of that.
[119] Fix | Delete
*
[120] Fix | Delete
* @return bool True on success and false on failure.
[121] Fix | Delete
*
[122] Fix | Delete
* @throws InvalidArgumentException
[123] Fix | Delete
* MUST be thrown if the $key string is not a legal value.
[124] Fix | Delete
*/
[125] Fix | Delete
public function set_data(string $key, array $value, ?int $ttl = null): bool
[126] Fix | Delete
{
[127] Fix | Delete
if ($ttl === null) {
[128] Fix | Delete
$ttl = 3600;
[129] Fix | Delete
}
[130] Fix | Delete
[131] Fix | Delete
// place internal cache expiration time
[132] Fix | Delete
$value['__cache_expiration_time'] = time() + $ttl;
[133] Fix | Delete
[134] Fix | Delete
return $this->cache->save($value);
[135] Fix | Delete
}
[136] Fix | Delete
[137] Fix | Delete
/**
[138] Fix | Delete
* Delete an item from the cache by its unique key.
[139] Fix | Delete
*
[140] Fix | Delete
* Equivalent to \Psr\SimpleCache\CacheInterface::delete()
[141] Fix | Delete
* <code>
[142] Fix | Delete
* public function delete(string $key): bool;
[143] Fix | Delete
* </code>
[144] Fix | Delete
*
[145] Fix | Delete
* @param string $key The unique cache key of the item to delete.
[146] Fix | Delete
*
[147] Fix | Delete
* @return bool True if the item was successfully removed. False if there was an error.
[148] Fix | Delete
*
[149] Fix | Delete
* @throws InvalidArgumentException
[150] Fix | Delete
* MUST be thrown if the $key string is not a legal value.
[151] Fix | Delete
*/
[152] Fix | Delete
public function delete_data(string $key): bool
[153] Fix | Delete
{
[154] Fix | Delete
return $this->cache->unlink();
[155] Fix | Delete
}
[156] Fix | Delete
}
[157] Fix | Delete
[158] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function