1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace CL\PsrCache; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* @author Ivan Kerin <[email protected]> |
7
|
|
|
* @copyright 2014, Clippings Ltd. |
8
|
|
|
* @license http://spdx.org/licenses/BSD-3-Clause |
9
|
|
|
*/ |
10
|
|
|
class NullItem implements CacheItemInterface |
11
|
|
|
{ |
12
|
|
|
private $key; |
13
|
|
|
private $value; |
14
|
|
|
|
15
|
1 |
|
public function __construct($key) |
16
|
|
|
{ |
17
|
1 |
|
$this->key = $key; |
18
|
1 |
|
} |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Returns the key for the current cache item. |
22
|
|
|
* |
23
|
|
|
* The key is loaded by the Implementing Library, but should be available to |
24
|
|
|
* the higher level callers when needed. |
25
|
|
|
* |
26
|
|
|
* @return string |
27
|
|
|
* The key string for this cache item. |
28
|
|
|
*/ |
29
|
1 |
|
public function getKey() |
30
|
|
|
{ |
31
|
1 |
|
return $this->key; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Retrieves the value of the item from the cache associated with this objects key. |
36
|
|
|
* |
37
|
|
|
* The value returned must be identical to the value original stored by set(). |
38
|
|
|
* |
39
|
|
|
* if isHit() returns false, this method MUST return null. Note that null |
40
|
|
|
* is a legitimate cached value, so the isHit() method SHOULD be used to |
41
|
|
|
* differentiate between "null value was found" and "no value was found." |
42
|
|
|
* |
43
|
|
|
* @return mixed |
44
|
|
|
* The value corresponding to this cache item's key, or null if not found. |
45
|
|
|
*/ |
46
|
1 |
|
public function get() |
47
|
|
|
{ |
48
|
1 |
|
return $this->value; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Sets the value represented by this cache item. |
53
|
|
|
* |
54
|
|
|
* The $value argument may be any item that can be serialized by PHP, |
55
|
|
|
* although the method of serialization is left up to the Implementing |
56
|
|
|
* Library. |
57
|
|
|
* |
58
|
|
|
* Implementing Libraries MAY provide a default TTL if one is not specified. |
59
|
|
|
* If no TTL is specified and no default TTL has been set, the TTL MUST |
60
|
|
|
* be set to the maximum possible duration of the underlying storage |
61
|
|
|
* mechanism, or permanent if possible. |
62
|
|
|
* |
63
|
|
|
* @param mixed $value |
64
|
|
|
* The serializable value to be stored. |
65
|
|
|
* @param int|\DateTime $ttl |
66
|
|
|
* - If an integer is passed, it is interpreted as the number of seconds |
67
|
|
|
* after which the item MUST be considered expired. |
68
|
|
|
* - If a DateTime object is passed, it is interpreted as the point in |
69
|
|
|
* time after which the item MUST be considered expired. |
70
|
|
|
* - If no value is passed, a default value MAY be used. If none is set, |
71
|
|
|
* the value should be stored permanently or for as long as the |
72
|
|
|
* implementation allows. |
73
|
|
|
* @return static |
74
|
|
|
* The invoked object. |
75
|
|
|
*/ |
76
|
1 |
|
public function set($value, $ttl = null) |
77
|
|
|
{ |
78
|
1 |
|
$this->value = $value; |
79
|
|
|
|
80
|
1 |
|
return $this; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Saves a value into the cache. |
85
|
|
|
* |
86
|
|
|
* @return boolean |
87
|
|
|
* Returns true if the item was successfully saved, or false if there was |
88
|
|
|
* an error. |
89
|
|
|
*/ |
90
|
1 |
|
public function save() |
91
|
|
|
{ |
92
|
1 |
|
return true; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Confirms if the cache item lookup resulted in a cache hit. |
97
|
|
|
* |
98
|
|
|
* Note: This method MUST NOT have a race condition between calling isHit() |
99
|
|
|
* and calling get(). |
100
|
|
|
* |
101
|
|
|
* @return boolean |
102
|
|
|
* True if the request resulted in a cache hit. False otherwise. |
103
|
|
|
*/ |
104
|
1 |
|
public function isHit() |
105
|
|
|
{ |
106
|
1 |
|
return false; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Removes the current key from the cache. |
111
|
|
|
* |
112
|
|
|
* @return boolean |
113
|
|
|
* Returns true if the item was deleted or if it did not exist in the |
114
|
|
|
* first place, or false if there was an error. |
115
|
|
|
*/ |
116
|
1 |
|
public function delete() |
117
|
|
|
{ |
118
|
1 |
|
return true; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Confirms if the cache item exists in the cache. |
123
|
|
|
* |
124
|
|
|
* Note: This method MAY avoid retrieving the cached value for performance |
125
|
|
|
* reasons, which could result in a race condition between exists() and get(). |
126
|
|
|
* To avoid that potential race condition use isHit() instead. |
127
|
|
|
* |
128
|
|
|
* @return boolean |
129
|
|
|
* True if item exists in the cache, false otherwise. |
130
|
|
|
*/ |
131
|
1 |
|
public function exists() |
132
|
|
|
{ |
133
|
1 |
|
return false; |
134
|
|
|
} |
135
|
|
|
} |
136
|
|
|
|