3 namespace Friendica\Core\Cache;
6 use Friendica\Core\Cache;
9 * Implementation of the IMemoryCacheDriver mainly for testing purpose
13 * @package Friendica\Core\Cache
15 class ArrayCache extends AbstractCacheDriver implements IMemoryCacheDriver
17 use TraitCompareDelete;
19 /** @var array Array with the cached data */
20 protected $cachedData = array();
25 public function getAllKeys($prefix = null)
27 return $this->filterArrayKeysByPrefix($this->cachedData, $prefix);
33 public function get($key)
35 if (isset($this->cachedData[$key])) {
36 return $this->cachedData[$key];
44 public function set($key, $value, $ttl = Cache::FIVE_MINUTES)
46 $this->cachedData[$key] = $value;
53 public function delete($key)
55 unset($this->cachedData[$key]);
62 public function clear($outdated = true)
64 // Array doesn't support TTL so just don't delete something
69 $this->cachedData = [];
76 public function add($key, $value, $ttl = Cache::FIVE_MINUTES)
78 if (isset($this->cachedData[$key])) {
81 return $this->set($key, $value, $ttl);
88 public function compareSet($key, $oldValue, $newValue, $ttl = Cache::FIVE_MINUTES)
90 if ($this->get($key) === $oldValue) {
91 return $this->set($key, $newValue);