3 namespace Friendica\Core\Cache;
5 use Friendica\Core\BaseCache;
8 * Implementation of the IMemoryCache mainly for testing purpose
12 * @package Friendica\Core\Cache
14 class ArrayCache extends BaseCache implements IMemoryCache
16 use TraitCompareDelete;
18 /** @var array Array with the cached data */
19 protected $cachedData = array();
24 public function getAllKeys($prefix = null)
26 return $this->filterArrayKeysByPrefix(array_keys($this->cachedData), $prefix);
32 public function get($key)
34 if (isset($this->cachedData[$key])) {
35 return $this->cachedData[$key];
43 public function set($key, $value, $ttl = Duration::FIVE_MINUTES)
45 $this->cachedData[$key] = $value;
52 public function delete($key)
54 unset($this->cachedData[$key]);
61 public function clear($outdated = true)
63 // Array doesn't support TTL so just don't delete something
68 $this->cachedData = [];
75 public function add($key, $value, $ttl = Duration::FIVE_MINUTES)
77 if (isset($this->cachedData[$key])) {
80 return $this->set($key, $value, $ttl);
87 public function compareSet($key, $oldValue, $newValue, $ttl = Duration::FIVE_MINUTES)
89 if ($this->get($key) === $oldValue) {
90 return $this->set($key, $newValue);
99 public function getName()