1 | <?php |
||
18 | class Item extends AbstractItem |
||
19 | { |
||
20 | /** |
||
21 | * The time the object expires at |
||
22 | * |
||
23 | * @var \DateTimeInterface |
||
24 | * @since __DEPLOY_VERSION__ |
||
25 | */ |
||
26 | private $expiration; |
||
27 | |||
28 | /** |
||
29 | * The key for the cache item. |
||
30 | * |
||
31 | * @var string |
||
32 | * @since 1.0 |
||
33 | */ |
||
34 | private $key; |
||
35 | |||
36 | /** |
||
37 | * The value of the cache item. |
||
38 | * |
||
39 | * @var mixed |
||
40 | * @since 1.0 |
||
41 | */ |
||
42 | private $value; |
||
43 | |||
44 | /** |
||
45 | * Whether the cache item has been hit. |
||
46 | * |
||
47 | * @var boolean |
||
48 | * @since 1.0 |
||
49 | */ |
||
50 | private $hit = false; |
||
51 | |||
52 | /** |
||
53 | * Class constructor. |
||
54 | * |
||
55 | * @param string $key The key for the cache item. |
||
56 | * @param \DateInterval|\DateTimeInterface|integer|null $ttl The expiry time for the cache item in seconds or as a datetime object |
||
57 | * |
||
58 | * @since 1.0 |
||
59 | */ |
||
60 | 54 | public function __construct($key, $ttl = null) |
|
77 | |||
78 | /** |
||
79 | * Confirms if the cache item exists in the cache. |
||
80 | * |
||
81 | * Note: This method MAY avoid retrieving the cached value for performance |
||
82 | * reasons, which could result in a race condition between exists() and get(). |
||
83 | * To avoid that potential race condition use isHit() instead. |
||
84 | * |
||
85 | * @return boolean |
||
86 | * |
||
87 | * @since __DEPLOY_VERSION__ |
||
88 | */ |
||
89 | public function exists() |
||
93 | |||
94 | /** |
||
95 | * Returns the key for the current cache item. |
||
96 | * |
||
97 | * @return string The key string for this cache item. |
||
98 | * |
||
99 | * @since 1.0 |
||
100 | */ |
||
101 | 39 | public function getKey() |
|
105 | |||
106 | /** |
||
107 | * Retrieves the value of the item from the cache associated with this object's key. |
||
108 | * |
||
109 | * @return mixed The value corresponding to this cache item's key, or null if not found. |
||
110 | * |
||
111 | * @since 1.0 |
||
112 | */ |
||
113 | 41 | public function get() |
|
117 | |||
118 | /** |
||
119 | * Sets the value represented by this cache item. |
||
120 | * |
||
121 | * If the value is set, we are assuming that there was a valid hit on the cache for the given key. |
||
122 | * |
||
123 | * @param mixed $value The serializable value to be stored. |
||
124 | * |
||
125 | * @return $this |
||
126 | * |
||
127 | * @since 1.0 |
||
128 | */ |
||
129 | 49 | public function set($value) |
|
136 | |||
137 | /** |
||
138 | * Confirms if the cache item lookup resulted in a cache hit. |
||
139 | * |
||
140 | * @return boolean True if the request resulted in a cache hit. False otherwise. |
||
141 | * |
||
142 | * @since 1.0 |
||
143 | */ |
||
144 | 33 | public function isHit() |
|
148 | |||
149 | /** |
||
150 | * Sets the expiration time for this cache item. |
||
151 | * |
||
152 | * @param \DateTimeInterface|null $expiration The point in time after which the item MUST be considered expired. |
||
153 | * If null is passed explicitly, a default value MAY be used. If none is |
||
154 | * set, the value should be stored permanently or for as long as the |
||
155 | * implementation allows. |
||
156 | * |
||
157 | * @return $this |
||
158 | * |
||
159 | * @since __DEPLOY_VERSION__ |
||
160 | * @throws InvalidArgumentException |
||
161 | */ |
||
162 | public function expiresAt($expiration) |
||
179 | |||
180 | /** |
||
181 | * Sets the expiration time for this cache item. |
||
182 | * |
||
183 | * @param int|\DateInterval|null $time The period of time from the present after which the item MUST be considered |
||
184 | * expired. An integer parameter is understood to be the time in seconds until |
||
185 | * expiration. |
||
186 | * |
||
187 | * @return $this |
||
188 | * |
||
189 | * @since __DEPLOY_VERSION__ |
||
190 | */ |
||
191 | 54 | public function expiresAfter($time) |
|
209 | |||
210 | /** |
||
211 | * Returns the expiration time of a not-yet-expired cache item. |
||
212 | * |
||
213 | * If this cache item is a Cache Miss, this method MAY return the time at which the item expired or the current time if that is not available. |
||
214 | * |
||
215 | * @return \DateTimeInterface The timestamp at which this cache item will expire. |
||
216 | * |
||
217 | * @since __DEPLOY_VERSION__ |
||
218 | */ |
||
219 | 21 | public function getExpiration(): \DateTimeInterface |
|
223 | } |
||
224 |