| 1 | <?php |
||
| 22 | class Cache implements ProviderInterface |
||
| 23 | { |
||
| 24 | const DEFAULT_LIFETIME = 30; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @var CacheProvider |
||
| 28 | */ |
||
| 29 | protected $cache; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @var int |
||
| 33 | */ |
||
| 34 | protected $lifetime; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Cache constructor. |
||
| 38 | * |
||
| 39 | * @param CacheProvider $cache cache |
||
| 40 | * @param int $lifetime lifetime |
||
| 41 | */ |
||
| 42 | public function __construct(CacheProvider $cache, int $lifetime = self::DEFAULT_LIFETIME) |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @param string $key key |
||
| 50 | * |
||
| 51 | * @return int|null |
||
| 52 | */ |
||
| 53 | public function fetch(string $key)/*: ?int*/ |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @param string $key key |
||
| 60 | * @param int $value value |
||
| 61 | * |
||
| 62 | * @return bool |
||
| 63 | */ |
||
| 64 | public function save(string $key, int $value): bool |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @param string $key key |
||
| 71 | * |
||
| 72 | * @return string |
||
| 73 | */ |
||
| 74 | protected static function prepareKey(string $key): string |
||
| 78 | } |