├── LICENSE.md ├── README.md ├── composer.json └── src ├── CacheException.php ├── CacheInterface.php └── InvalidArgumentException.php /LICENSE.md: -------------------------------------------------------------------------------- 1 | # The MIT License (MIT) 2 | 3 | Copyright (c) 2016 PHP Framework Interoperability Group 4 | 5 | > Permission is hereby granted, free of charge, to any person obtaining a copy 6 | > of this software and associated documentation files (the "Software"), to deal 7 | > in the Software without restriction, including without limitation the rights 8 | > to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | > copies of the Software, and to permit persons to whom the Software is 10 | > furnished to do so, subject to the following conditions: 11 | > 12 | > The above copyright notice and this permission notice shall be included in 13 | > all copies or substantial portions of the Software. 14 | > 15 | > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | > IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | > FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | > AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | > LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | > OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | > THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | PHP FIG Simple Cache PSR 2 | ======================== 3 | 4 | This repository holds all interfaces related to PSR-16. 5 | 6 | Note that this is not a cache implementation of its own. It is merely an interface that describes a cache implementation. See [the specification](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-16-simple-cache.md) for more details. 7 | 8 | You can find implementations of the specification by looking for packages providing the [psr/simple-cache-implementation](https://packagist.org/providers/psr/simple-cache-implementation) virtual package. 9 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "psr/simple-cache", 3 | "description": "Common interfaces for simple caching", 4 | "keywords": ["psr", "psr-16", "cache", "simple-cache", "caching"], 5 | "license": "MIT", 6 | "authors": [ 7 | { 8 | "name": "PHP-FIG", 9 | "homepage": "https://www.php-fig.org/" 10 | } 11 | ], 12 | "require": { 13 | "php": ">=8.0.0" 14 | }, 15 | "autoload": { 16 | "psr-4": { 17 | "Psr\\SimpleCache\\": "src/" 18 | } 19 | }, 20 | "extra": { 21 | "branch-alias": { 22 | "dev-master": "3.0.x-dev" 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/CacheException.php: -------------------------------------------------------------------------------- 1 | $keys A list of keys that can be obtained in a single operation. 59 | * @param mixed $default Default value to return for keys that do not exist. 60 | * 61 | * @return iterable A list of key => value pairs. Cache keys that do not exist or are stale will have $default as value. 62 | * 63 | * @throws \Psr\SimpleCache\InvalidArgumentException 64 | * MUST be thrown if $keys is neither an array nor a Traversable, 65 | * or if any of the $keys are not a legal value. 66 | */ 67 | public function getMultiple(iterable $keys, mixed $default = null): iterable; 68 | 69 | /** 70 | * Persists a set of key => value pairs in the cache, with an optional TTL. 71 | * 72 | * @param iterable $values A list of key => value pairs for a multiple-set operation. 73 | * @param null|int|\DateInterval $ttl Optional. The TTL value of this item. If no value is sent and 74 | * the driver supports TTL then the library may set a default value 75 | * for it or let the driver take care of that. 76 | * 77 | * @return bool True on success and false on failure. 78 | * 79 | * @throws \Psr\SimpleCache\InvalidArgumentException 80 | * MUST be thrown if $values is neither an array nor a Traversable, 81 | * or if any of the $values are not a legal value. 82 | */ 83 | public function setMultiple(iterable $values, null|int|\DateInterval $ttl = null): bool; 84 | 85 | /** 86 | * Deletes multiple cache items in a single operation. 87 | * 88 | * @param iterable $keys A list of string-based keys to be deleted. 89 | * 90 | * @return bool True if the items were successfully removed. False if there was an error. 91 | * 92 | * @throws \Psr\SimpleCache\InvalidArgumentException 93 | * MUST be thrown if $keys is neither an array nor a Traversable, 94 | * or if any of the $keys are not a legal value. 95 | */ 96 | public function deleteMultiple(iterable $keys): bool; 97 | 98 | /** 99 | * Determines whether an item is present in the cache. 100 | * 101 | * NOTE: It is recommended that has() is only to be used for cache warming type purposes 102 | * and not to be used within your live applications operations for get/set, as this method 103 | * is subject to a race condition where your has() will return true and immediately after, 104 | * another script can remove it making the state of your app out of date. 105 | * 106 | * @param string $key The cache item key. 107 | * 108 | * @return bool 109 | * 110 | * @throws \Psr\SimpleCache\InvalidArgumentException 111 | * MUST be thrown if the $key string is not a legal value. 112 | */ 113 | public function has(string $key): bool; 114 | } 115 | -------------------------------------------------------------------------------- /src/InvalidArgumentException.php: -------------------------------------------------------------------------------- 1 |