]> 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 cc77d9bfd0dc7e35598130af672287454ffdd25c..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
         *
@@ -107,12 +132,12 @@ class Cache extends \Friendica\BaseObject
        /**
         * @brief Remove outdated data from the cache
         *
-        * @param integer $max_level The maximum cache level that is to be cleared
+        * @param boolean $outdated just remove outdated values
         *
         * @return void
         */
-       public static function clear()
+       public static function clear($outdated = true)
        {
-               return self::getDriver()->clear();
+               return self::getDriver()->clear($outdated);
        }
 }