[ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 <?php 2 3 // SPDX-FileCopyrightText: 2004-2023 Ryan Parman, Sam Sneddon, Ryan McCue 4 // SPDX-License-Identifier: BSD-3-Clause 5 6 declare(strict_types=1); 7 8 namespace SimplePie\Cache; 9 10 use Psr\SimpleCache\CacheInterface; 11 use Psr\SimpleCache\InvalidArgumentException; 12 use Throwable; 13 14 /** 15 * Caches data into a PSR-16 cache implementation 16 * 17 * @internal 18 */ 19 final class Psr16 implements DataCache 20 { 21 /** 22 * PSR-16 cache implementation 23 * 24 * @var CacheInterface 25 */ 26 private $cache; 27 28 /** 29 * PSR-16 cache implementation 30 * 31 * @param CacheInterface $cache 32 */ 33 public function __construct(CacheInterface $cache) 34 { 35 $this->cache = $cache; 36 } 37 38 /** 39 * Fetches a value from the cache. 40 * 41 * Equivalent to \Psr\SimpleCache\CacheInterface::get() 42 * <code> 43 * public function get(string $key, mixed $default = null): mixed; 44 * </code> 45 * 46 * @param string $key The unique key of this item in the cache. 47 * @param mixed $default Default value to return if the key does not exist. 48 * 49 * @return array|mixed The value of the item from the cache, or $default in case of cache miss. 50 * 51 * @throws InvalidArgumentException&Throwable 52 * MUST be thrown if the $key string is not a legal value. 53 */ 54 public function get_data(string $key, $default = null) 55 { 56 $data = $this->cache->get($key, $default); 57 58 if (!is_array($data) || $data === $default) { 59 return $default; 60 } 61 62 return $data; 63 } 64 65 /** 66 * Persists data in the cache, uniquely referenced by a key with an optional expiration TTL time. 67 * 68 * Equivalent to \Psr\SimpleCache\CacheInterface::set() 69 * <code> 70 * public function set(string $key, mixed $value, null|int|\DateInterval $ttl = null): bool; 71 * </code> 72 * 73 * @param string $key The key of the item to store. 74 * @param array<mixed> $value The value of the item to store, must be serializable. 75 * @param null|int $ttl Optional. The TTL value of this item. If no value is sent and 76 * the driver supports TTL then the library may set a default value 77 * for it or let the driver take care of that. 78 * 79 * @return bool True on success and false on failure. 80 * 81 * @throws InvalidArgumentException&Throwable 82 * MUST be thrown if the $key string is not a legal value. 83 */ 84 public function set_data(string $key, array $value, ?int $ttl = null): bool 85 { 86 return $this->cache->set($key, $value, $ttl); 87 } 88 89 /** 90 * Delete an item from the cache by its unique key. 91 * 92 * Equivalent to \Psr\SimpleCache\CacheInterface::delete() 93 * <code> 94 * public function delete(string $key): bool; 95 * </code> 96 * 97 * @param string $key The unique cache key of the item to delete. 98 * 99 * @return bool True if the item was successfully removed. False if there was an error. 100 * 101 * @throws InvalidArgumentException&Throwable 102 * MUST be thrown if the $key string is not a legal value. 103 */ 104 public function delete_data(string $key): bool 105 { 106 return $this->cache->delete($key); 107 } 108 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated : Thu Sep 18 08:20:05 2025 | Cross-referenced by PHPXref |