]> git.mxchange.org Git - friendica.git/blobdiff - src/Core/Cache/ArrayCache.php
Merge pull request #1 from friendica/develop
[friendica.git] / src / Core / Cache / ArrayCache.php
index ec9f3a2577fda4e0691c67b1452691ad75d25a8b..01157f7f8dbd3e7167c688d30ee41f08c8c47fa3 100644 (file)
@@ -1,24 +1,46 @@
 <?php
+/**
+ * @copyright Copyright (C) 2020, Friendica
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
 
 namespace Friendica\Core\Cache;
 
-
-use Friendica\Core\Cache;
+use Friendica\Core\BaseCache;
 
 /**
- * Implementation of the IMemoryCacheDriver mainly for testing purpose
- *
- * Class ArrayCache
- *
- * @package Friendica\Core\Cache
+ * Implementation of the IMemoryCache mainly for testing purpose
  */
-class ArrayCache extends AbstractCacheDriver implements IMemoryCacheDriver
+class ArrayCache extends BaseCache implements IMemoryCache
 {
        use TraitCompareDelete;
 
        /** @var array Array with the cached data */
        protected $cachedData = array();
 
+       /**
+        * (@inheritdoc)
+        */
+       public function getAllKeys($prefix = null)
+       {
+               return $this->filterArrayKeysByPrefix(array_keys($this->cachedData), $prefix);
+       }
+
        /**
         * (@inheritdoc)
         */
@@ -33,7 +55,7 @@ class ArrayCache extends AbstractCacheDriver implements IMemoryCacheDriver
        /**
         * (@inheritdoc)
         */
-       public function set($key, $value, $ttl = Cache::FIVE_MINUTES)
+       public function set($key, $value, $ttl = Duration::FIVE_MINUTES)
        {
                $this->cachedData[$key] = $value;
                return true;
@@ -51,8 +73,13 @@ class ArrayCache extends AbstractCacheDriver implements IMemoryCacheDriver
        /**
         * (@inheritdoc)
         */
-       public function clear()
+       public function clear($outdated = true)
        {
+               // Array doesn't support TTL so just don't delete something
+               if ($outdated) {
+                       return true;
+               }
+
                $this->cachedData = [];
                return true;
        }
@@ -60,7 +87,7 @@ class ArrayCache extends AbstractCacheDriver implements IMemoryCacheDriver
        /**
         * (@inheritdoc)
         */
-       public function add($key, $value, $ttl = Cache::FIVE_MINUTES)
+       public function add($key, $value, $ttl = Duration::FIVE_MINUTES)
        {
                if (isset($this->cachedData[$key])) {
                        return false;
@@ -72,7 +99,7 @@ class ArrayCache extends AbstractCacheDriver implements IMemoryCacheDriver
        /**
         * (@inheritdoc)
         */
-       public function compareSet($key, $oldValue, $newValue, $ttl = Cache::FIVE_MINUTES)
+       public function compareSet($key, $oldValue, $newValue, $ttl = Duration::FIVE_MINUTES)
        {
                if ($this->get($key) === $oldValue) {
                        return $this->set($key, $newValue);
@@ -80,4 +107,12 @@ class ArrayCache extends AbstractCacheDriver implements IMemoryCacheDriver
                        return false;
                }
        }
+
+       /**
+        * {@inheritDoc}
+        */
+       public function getName()
+       {
+               return Type::ARRAY;
+       }
 }