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 get($key)
27 if (isset($this->cachedData[$key])) {
28 return $this->cachedData[$key];
36 public function set($key, $value, $ttl = Cache::FIVE_MINUTES)
38 $this->cachedData[$key] = $value;
45 public function delete($key)
47 unset($this->cachedData[$key]);
54 public function clear($outdated = true)
56 $this->cachedData = [];
63 public function add($key, $value, $ttl = Cache::FIVE_MINUTES)
65 if (isset($this->cachedData[$key])) {
68 return $this->set($key, $value, $ttl);
75 public function compareSet($key, $oldValue, $newValue, $ttl = Cache::FIVE_MINUTES)
77 if ($this->get($key) === $oldValue) {
78 return $this->set($key, $newValue);