3 namespace Friendica\Core\Cache;
6 * Implementation of the IMemoryCache mainly for testing purpose
10 * @package Friendica\Core\Cache
12 class ArrayCache extends Cache implements IMemoryCache
14 use TraitCompareDelete;
16 /** @var array Array with the cached data */
17 protected $cachedData = array();
22 public function getAllKeys($prefix = null)
24 return $this->filterArrayKeysByPrefix($this->cachedData, $prefix);
30 public function get($key)
32 if (isset($this->cachedData[$key])) {
33 return $this->cachedData[$key];
41 public function set($key, $value, $ttl = Cache::FIVE_MINUTES)
43 $this->cachedData[$key] = $value;
50 public function delete($key)
52 unset($this->cachedData[$key]);
59 public function clear($outdated = true)
61 // Array doesn't support TTL so just don't delete something
66 $this->cachedData = [];
73 public function add($key, $value, $ttl = Cache::FIVE_MINUTES)
75 if (isset($this->cachedData[$key])) {
78 return $this->set($key, $value, $ttl);
85 public function compareSet($key, $oldValue, $newValue, $ttl = Cache::FIVE_MINUTES)
87 if ($this->get($key) === $oldValue) {
88 return $this->set($key, $newValue);
94 public function __toString()
96 return self::TYPE_ARRAY;