1 | <?php |
||
22 | abstract class AbstractStorage implements CacheStorageInterface |
||
23 | { |
||
24 | /** |
||
25 | * @var DateInterval |
||
26 | */ |
||
27 | private $ttl; |
||
28 | |||
29 | /** |
||
30 | * Abstract Storage constructor. |
||
31 | * @param DateInterval $ttl |
||
32 | */ |
||
33 | 25 | public function __construct(DateInterval $ttl) |
|
37 | |||
38 | /** |
||
39 | * With default ttl. |
||
40 | * |
||
41 | * @param DateInterval $ttl |
||
42 | * @return CacheStorageInterface |
||
43 | */ |
||
44 | 1 | public function withTtl(DateInterval $ttl){ |
|
49 | |||
50 | /** |
||
51 | * Get ttl as integer. |
||
52 | * |
||
53 | * @param null|int $ttl |
||
54 | * @return int |
||
55 | */ |
||
56 | 9 | public function getTtlTimestamp($ttl = null){ |
|
66 | |||
67 | /** |
||
68 | * Get ttl as integer. |
||
69 | * |
||
70 | * @return DateInterval |
||
71 | */ |
||
72 | 2 | public function getTtl(){ |
|
75 | |||
76 | /** |
||
77 | * Persists data in the cache, uniquely referenced by a key with an optional expiration TTL time. |
||
78 | * |
||
79 | * @param string $key The key of the item to store. |
||
80 | * @param mixed $value The value of the item to store, must be serializable. |
||
81 | * @param null|int $ttl Optional. The TTL value of this item. If no value is sent and |
||
82 | * the driver supports TTL then the library may set a default value |
||
83 | * for it or let the driver take care of that. |
||
84 | * |
||
85 | * @return bool True on success and false on failure. |
||
86 | */ |
||
87 | abstract public function set($key, $value, $ttl = null); |
||
88 | |||
89 | /** |
||
90 | * Determines whether an item is present in the cache. |
||
91 | * |
||
92 | * NOTE: It is recommended that has() is only to be used for cache warming type purposes |
||
93 | * and not to be used within your live applications operations for get/set, as this method |
||
94 | * is subject to a race condition where your has() will return true and immediately after, |
||
95 | * another script can remove it making the state of your app out of date. |
||
96 | * |
||
97 | * @param string $key The cache item key. |
||
98 | * |
||
99 | * @return bool |
||
100 | */ |
||
101 | abstract public function has($key); |
||
102 | |||
103 | /** |
||
104 | * Fetches a value from the cache. |
||
105 | * |
||
106 | * @param string $key The unique key of this item in the cache. |
||
107 | * |
||
108 | * @return mixed The value of the item from the cache, or $default in case of cache miss. |
||
109 | * |
||
110 | */ |
||
111 | abstract public function get($key); |
||
112 | |||
113 | /** |
||
114 | * Delete an item from the cache by its unique key. |
||
115 | * |
||
116 | * @param string $key The unique cache key of the item to delete. |
||
117 | * |
||
118 | * @return bool True if the item was successfully removed. False if there was an error. |
||
119 | */ |
||
120 | abstract public function delete($key); |
||
121 | |||
122 | /** |
||
123 | * Wipes clean the entire cache's keys. |
||
124 | * |
||
125 | * @return bool True on success and false on failure. |
||
126 | */ |
||
127 | abstract public function clear(); |
||
128 | |||
129 | } |
||
130 |