@@ -57,7 +57,7 @@ public function __construct(\Memcached $memcached, int $initialTtl = 300)
57
57
*/
58
58
public function save (Key $ key )
59
59
{
60
- $ token = $ this ->getToken ($ key );
60
+ $ token = $ this ->getUniqueToken ($ key );
61
61
$ key ->reduceLifetime ($ this ->initialTtl );
62
62
if (!$ this ->memcached ->add ((string ) $ key , $ token , (int ) ceil ($ this ->initialTtl ))) {
63
63
// the lock is already acquired. It could be us. Let's try to put off.
@@ -80,13 +80,13 @@ public function waitAndSave(Key $key)
80
80
public function putOffExpiration (Key $ key , $ ttl )
81
81
{
82
82
if ($ ttl < 1 ) {
83
- throw new InvalidArgumentException (sprintf ('%s() expects a TTL greater or equals to 1. Got %s. ' , __METHOD__ , $ ttl ));
83
+ throw new InvalidArgumentException (sprintf ('%s() expects a TTL greater or equals to 1 second . Got %s. ' , __METHOD__ , $ ttl ));
84
84
}
85
85
86
86
// Interface defines a float value but Store required an integer.
87
87
$ ttl = (int ) ceil ($ ttl );
88
88
89
- $ token = $ this ->getToken ($ key );
89
+ $ token = $ this ->getUniqueToken ($ key );
90
90
91
91
list ($ value , $ cas ) = $ this ->getValueAndCas ($ key );
92
92
@@ -120,7 +120,7 @@ public function putOffExpiration(Key $key, $ttl)
120
120
*/
121
121
public function delete (Key $ key )
122
122
{
123
- $ token = $ this ->getToken ($ key );
123
+ $ token = $ this ->getUniqueToken ($ key );
124
124
125
125
list ($ value , $ cas ) = $ this ->getValueAndCas ($ key );
126
126
@@ -144,13 +144,10 @@ public function delete(Key $key)
144
144
*/
145
145
public function exists (Key $ key )
146
146
{
147
- return $ this ->memcached ->get ((string ) $ key ) === $ this ->getToken ($ key );
147
+ return $ this ->memcached ->get ((string ) $ key ) === $ this ->getUniqueToken ($ key );
148
148
}
149
149
150
- /**
151
- * Retrieve an unique token for the given key.
152
- */
153
- private function getToken (Key $ key ): string
150
+ private function getUniqueToken (Key $ key ): string
154
151
{
155
152
if (!$ key ->hasState (__CLASS__ )) {
156
153
$ token = base64_encode (random_bytes (32 ));
0 commit comments