Skip to content

Commit 8aae9ce

Browse files
committed
* Switched to using psr/simple-cache from psr/cache
1 parent 47ad0b8 commit 8aae9ce

File tree

10 files changed

+171
-303
lines changed

10 files changed

+171
-303
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ with dev requirements for them to work.
7777
# External Documentation
7878
Links to documentation for external dependencies:
7979
* [PHP Docs](http://php.net/)
80-
* [Logging PSR-3](http://www.php-fig.org/psr/psr-3/)
81-
* [Cache PSR-6](http://www.php-fig.org/psr/psr-6/)
80+
* [Logging PSR-3](http://www.php-fig.org/psr/psr-3/) ([GitHub page](https://github.com/php-fig/log))
81+
* [Simple Cache PSR-16](http://www.php-fig.org/psr/psr-16/) ([GitHub page](https://github.com/php-fig/simple-cache))
8282

8383
Links to documentation for development only external dependencies:
8484
* [cache/cache](http://www.php-cache.com/en/latest/)

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
],
1212
"require": {
1313
"php": ">=7.0",
14-
"psr/cache": "~1.0",
14+
"psr/simple-cache": "~1.0.0",
1515
"psr/log": "~1.0"
1616
},
1717
"autoload": {

src/Cache/NullCache.php

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
<?php
2+
3+
namespace MadeSimple\TaskWorker\Cache;
4+
5+
use DateInterval;
6+
use Psr\SimpleCache\CacheInterface;
7+
8+
/**
9+
* Class NullCache
10+
*
11+
* @package MadeSimple\TaskWorker\Cache
12+
* @author Peter Scopes
13+
*/
14+
class NullCache implements CacheInterface
15+
{
16+
17+
/**
18+
* Fetches a value from the cache.
19+
*
20+
* @param string $key The unique key of this item in the cache.
21+
* @param mixed $default Default value to return if the key does not exist.
22+
*
23+
* @return mixed The value of the item from the cache, or $default in case of cache miss.
24+
*
25+
* @throws \Psr\SimpleCache\InvalidArgumentException
26+
* MUST be thrown if the $key string is not a legal value.
27+
*/
28+
public function get($key, $default = null)
29+
{
30+
return null;
31+
}
32+
33+
/**
34+
* Persists data in the cache, uniquely referenced by a key with an optional expiration TTL time.
35+
*
36+
* @param string $key The key of the item to store.
37+
* @param mixed $value The value of the item to store, must be serializable.
38+
* @param null|int|DateInterval $ttl Optional. The TTL value of this item. If no value is sent and
39+
* the driver supports TTL then the library may set a default value
40+
* for it or let the driver take care of that.
41+
*
42+
* @return bool True on success and false on failure.
43+
*
44+
* @throws \Psr\SimpleCache\InvalidArgumentException
45+
* MUST be thrown if the $key string is not a legal value.
46+
*/
47+
public function set($key, $value, $ttl = null)
48+
{
49+
return true;
50+
}
51+
52+
/**
53+
* Delete an item from the cache by its unique key.
54+
*
55+
* @param string $key The unique cache key of the item to delete.
56+
*
57+
* @return bool True if the item was successfully removed. False if there was an error.
58+
*
59+
* @throws \Psr\SimpleCache\InvalidArgumentException
60+
* MUST be thrown if the $key string is not a legal value.
61+
*/
62+
public function delete($key)
63+
{
64+
return true;
65+
}
66+
67+
/**
68+
* Wipes clean the entire cache's keys.
69+
*
70+
* @return bool True on success and false on failure.
71+
*/
72+
public function clear()
73+
{
74+
return true;
75+
}
76+
77+
/**
78+
* Obtains multiple cache items by their unique keys.
79+
*
80+
* @param iterable $keys A list of keys that can obtained in a single operation.
81+
* @param mixed $default Default value to return for keys that do not exist.
82+
*
83+
* @return iterable A list of key => value pairs. Cache keys that do not exist or are stale will have $default as value.
84+
*
85+
* @throws \Psr\SimpleCache\InvalidArgumentException
86+
* MUST be thrown if $keys is neither an array nor a Traversable,
87+
* or if any of the $keys are not a legal value.
88+
*/
89+
public function getMultiple($keys, $default = null)
90+
{
91+
return array_fill_keys($keys, null);
92+
}
93+
94+
/**
95+
* Persists a set of key => value pairs in the cache, with an optional TTL.
96+
*
97+
* @param iterable $values A list of key => value pairs for a multiple-set operation.
98+
* @param null|int|DateInterval $ttl Optional. The TTL value of this item. If no value is sent and
99+
* the driver supports TTL then the library may set a default value
100+
* for it or let the driver take care of that.
101+
*
102+
* @return bool True on success and false on failure.
103+
*
104+
* @throws \Psr\SimpleCache\InvalidArgumentException
105+
* MUST be thrown if $values is neither an array nor a Traversable,
106+
* or if any of the $values are not a legal value.
107+
*/
108+
public function setMultiple($values, $ttl = null)
109+
{
110+
return true;
111+
}
112+
113+
/**
114+
* Deletes multiple cache items in a single operation.
115+
*
116+
* @param iterable $keys A list of string-based keys to be deleted.
117+
*
118+
* @return bool True if the items were successfully removed. False if there was an error.
119+
*
120+
* @throws \Psr\SimpleCache\InvalidArgumentException
121+
* MUST be thrown if $keys is neither an array nor a Traversable,
122+
* or if any of the $keys are not a legal value.
123+
*/
124+
public function deleteMultiple($keys)
125+
{
126+
return true;
127+
}
128+
129+
/**
130+
* Determines whether an item is present in the cache.
131+
*
132+
* NOTE: It is recommended that has() is only to be used for cache warming type purposes
133+
* and not to be used within your live applications operations for get/set, as this method
134+
* is subject to a race condition where your has() will return true and immediately after,
135+
* another script can remove it making the state of your app out of date.
136+
*
137+
* @param string $key The cache item key.
138+
*
139+
* @return bool
140+
*
141+
* @throws \Psr\SimpleCache\InvalidArgumentException
142+
* MUST be thrown if the $key string is not a legal value.
143+
*/
144+
public function has($key)
145+
{
146+
return true;
147+
}
148+
}

src/Cache/NullCacheItem.php

Lines changed: 0 additions & 113 deletions
This file was deleted.

0 commit comments

Comments
 (0)