]> git.mxchange.org Git - friendica.git/blobdiff - src/Core/Cache.php
Changing Friendica\App\Mode from static methods to public methods
[friendica.git] / src / Core / Cache.php
index 81eacc80ff129d178af500d8a83b6d61bd0b2cb9..ea7807031fde7389479dfb2bad49c1d342094e2c 100644 (file)
@@ -23,13 +23,15 @@ class Cache extends \Friendica\BaseObject
        /**
         * @var Cache\ICacheDriver
         */
-       private static $driver = null;
+       private static $driver       = null;
+       public  static $driver_class = null;
+       public  static $driver_name  = null;
 
        public static function init()
        {
-               $driver_name = Config::get('system', 'cache_driver', 'database');
-
-               self::$driver = CacheDriverFactory::create($driver_name);
+               self::$driver_name  = Config::get('system', 'cache_driver', 'database');
+               self::$driver       = CacheDriverFactory::create(self::$driver_name);
+               self::$driver_class = get_class(self::$driver);
        }
 
        /**
@@ -46,6 +48,29 @@ class Cache extends \Friendica\BaseObject
                return self::$driver;
        }
 
+       /**
+        * @brief Returns all the cache keys sorted alphabetically
+        *
+        * @return array|null Null if the driver doesn't support this feature
+        */
+       public static function getAllKeys()
+       {
+               $time = microtime(true);
+
+               $return = self::getDriver()->getAllKeys();
+
+               // Keys are prefixed with the node hostname, let's remove it
+               array_walk($return, function (&$value) {
+                       $value = preg_replace('/^' . self::getApp()->get_hostname() . ':/', '', $value);
+               });
+
+               sort($return);
+
+               self::getApp()->save_timestamp($time, 'cache');
+
+               return $return;
+       }
+
        /**
         * @brief Fetch cached data according to the key
         *