1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* PHP version 5.5 |
5
|
|
|
* |
6
|
|
|
* @package Psr\Cache |
7
|
|
|
* @author Sergey V.Kuzin <[email protected]> |
8
|
|
|
* @license MIT |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Psr\Cache; |
12
|
|
|
|
13
|
|
|
class NullCacheItem implements CacheItemInterface |
14
|
|
|
{ |
15
|
|
|
protected $key; |
16
|
|
|
protected $value = null; |
17
|
|
|
|
18
|
|
|
public function __construct($key) |
19
|
|
|
{ |
20
|
|
|
$this->key = $key; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Returns the key for the current cache item. |
25
|
|
|
* |
26
|
|
|
* The key is loaded by the Implementing Library, but should be available to |
27
|
|
|
* the higher level callers when needed. |
28
|
|
|
* |
29
|
|
|
* @return string |
30
|
|
|
* The key string for this cache item. |
31
|
|
|
*/ |
32
|
|
|
public function getKey() |
33
|
|
|
{ |
34
|
|
|
return $this->key; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Retrieves the value of the item from the cache associated with this objects key. |
39
|
|
|
* |
40
|
|
|
* The value returned must be identical to the value original stored by set(). |
41
|
|
|
* |
42
|
|
|
* if isHit() returns false, this method MUST return null. Note that null |
43
|
|
|
* is a legitimate cached value, so the isHit() method SHOULD be used to |
44
|
|
|
* differentiate between "null value was found" and "no value was found." |
45
|
|
|
* |
46
|
|
|
* @return mixed |
47
|
|
|
* The value corresponding to this cache item's key, or null if not found. |
48
|
|
|
*/ |
49
|
|
|
public function get() |
50
|
|
|
{ |
51
|
|
|
return $this->value; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Sets the value represented by this cache item. |
56
|
|
|
* |
57
|
|
|
* The $value argument may be any item that can be serialized by PHP, |
58
|
|
|
* although the method of serialization is left up to the Implementing |
59
|
|
|
* Library. |
60
|
|
|
* |
61
|
|
|
* Implementing Libraries MAY provide a default TTL if one is not specified. |
62
|
|
|
* If no TTL is specified and no default TTL has been set, the TTL MUST |
63
|
|
|
* be set to the maximum possible duration of the underlying storage |
64
|
|
|
* mechanism, or permanent if possible. |
65
|
|
|
* |
66
|
|
|
* @param mixed $value |
67
|
|
|
* The serializable value to be stored. |
68
|
|
|
* @param int|\DateTime $ttl |
69
|
|
|
* - If an integer is passed, it is interpreted as the number of seconds |
70
|
|
|
* after which the item MUST be considered expired. |
71
|
|
|
* - If a DateTime object is passed, it is interpreted as the point in |
72
|
|
|
* time after which the item MUST be considered expired. |
73
|
|
|
* - If no value is passed, a default value MAY be used. If none is set, |
74
|
|
|
* the value should be stored permanently or for as long as the |
75
|
|
|
* implementation allows. |
76
|
|
|
* @return static |
77
|
|
|
* The invoked object. |
78
|
|
|
*/ |
79
|
|
|
public function set($value, $ttl = null) |
80
|
|
|
{ |
81
|
|
|
$this->value; |
82
|
|
|
return $this; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Confirms if the cache item lookup resulted in a cache hit. |
87
|
|
|
* |
88
|
|
|
* Note: This method MUST NOT have a race condition between calling isHit() |
89
|
|
|
* and calling get(). |
90
|
|
|
* |
91
|
|
|
* @return boolean |
92
|
|
|
* True if the request resulted in a cache hit. False otherwise. |
93
|
|
|
*/ |
94
|
|
|
public function isHit() |
95
|
|
|
{ |
96
|
|
|
return false; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Confirms if the cache item exists in the cache. |
101
|
|
|
* |
102
|
|
|
* Note: This method MAY avoid retrieving the cached value for performance |
103
|
|
|
* reasons, which could result in a race condition between exists() and get(). |
104
|
|
|
* To avoid that potential race condition use isHit() instead. |
105
|
|
|
* |
106
|
|
|
* @return boolean |
107
|
|
|
* True if item exists in the cache, false otherwise. |
108
|
|
|
*/ |
109
|
|
|
public function exists() |
110
|
|
|
{ |
111
|
|
|
return false; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Sets the expiration time this cache item. |
116
|
|
|
* |
117
|
|
|
* @param \DateTime|\DateTimeImmutable $expiration |
118
|
|
|
* The point in time after which the item MUST be considered expired. |
119
|
|
|
* If null is passed explicitly, a default value MAY be used. If none is set, |
120
|
|
|
* the value should be stored permanently or for as long as the |
121
|
|
|
* implementation allows. |
122
|
|
|
* |
123
|
|
|
* @return static |
124
|
|
|
* The called object. |
125
|
|
|
*/ |
126
|
|
|
public function expiresAt($expiration) |
127
|
|
|
{ |
128
|
|
|
return $this; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Sets the expiration time this cache item. |
133
|
|
|
* |
134
|
|
|
* @param int|\DateInterval $time |
135
|
|
|
* The period of time from the present after which the item MUST be considered |
136
|
|
|
* expired. An integer parameter is understood to be the time in seconds until |
137
|
|
|
* expiration. |
138
|
|
|
* |
139
|
|
|
* @return static |
140
|
|
|
* The called object. |
141
|
|
|
*/ |
142
|
|
|
public function expiresAfter($time) |
143
|
|
|
{ |
144
|
|
|
return $this; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* Returns the expiration time of a not-yet-expired cache item. |
149
|
|
|
* |
150
|
|
|
* If this cache item is a Cache Miss, this method MAY return the time at |
151
|
|
|
* which the item expired or the current time if that is not available. |
152
|
|
|
* |
153
|
|
|
* @return \DateTime |
154
|
|
|
* The timestamp at which this cache item will expire. |
155
|
|
|
*/ |
156
|
|
|
public function getExpiration() |
157
|
|
|
{ |
158
|
|
|
return new \DateTime(); |
159
|
|
|
} |
160
|
|
|
} |
161
|
|
|
|