3 * @file src/Core/Cache.php
5 namespace Friendica\Core;
7 use Friendica\BaseObject;
8 use Friendica\Core\Cache\Cache as CacheClass;
9 use Friendica\Core\Cache\ICache;
12 * @brief Class for storing data for a short time
14 class Cache extends BaseObject
16 /** @deprecated Use CacheClass::MONTH */
17 const MONTH = CacheClass::MONTH;
18 /** @deprecated Use CacheClass::WEEK */
19 const WEEK = CacheClass::WEEK;
20 /** @deprecated Use CacheClass::DAY */
21 const DAY = CacheClass::DAY;
22 /** @deprecated Use CacheClass::HOUR */
23 const HOUR = CacheClass::HOUR;
24 /** @deprecated Use CacheClass::HALF_HOUR */
25 const HALF_HOUR = CacheClass::HALF_HOUR;
26 /** @deprecated Use CacheClass::QUARTER_HOUR */
27 const QUARTER_HOUR = CacheClass::QUARTER_HOUR;
28 /** @deprecated Use CacheClass::FIVE_MINUTES */
29 const FIVE_MINUTES = CacheClass::FIVE_MINUTES;
30 /** @deprecated Use CacheClass::MINUTE */
31 const MINUTE = CacheClass::MINUTE;
32 /** @deprecated Use CacheClass::INFINITE */
33 const INFINITE = CacheClass::INFINITE;
36 * @brief Returns all the cache keys sorted alphabetically
38 * @param string $prefix Prefix of the keys (optional)
40 * @return array Empty if the driver doesn't support this feature
43 public static function getAllKeys($prefix = null)
45 return self::getClass(ICache::class)->getAllKeys($prefix);
49 * @brief Fetch cached data according to the key
51 * @param string $key The key to the cached data
53 * @return mixed Cached $value or "null" if not found
56 public static function get($key)
58 return self::getClass(ICache::class)->get($key);
62 * @brief Put data in the cache according to the key
64 * The input $value can have multiple formats.
66 * @param string $key The key to the cached data
67 * @param mixed $value The value that is about to be stored
68 * @param integer $duration The cache lifespan
73 public static function set($key, $value, $duration = CacheClass::MONTH)
75 return self::getClass(ICache::class)->set($key, $value, $duration);
79 * @brief Delete a value from the cache
81 * @param string $key The key to the cached data
86 public static function delete($key)
88 return self::getClass(ICache::class)->delete($key);
92 * @brief Remove outdated data from the cache
94 * @param boolean $outdated just remove outdated values
99 public static function clear($outdated = true)
101 return self::getClass(ICache::class)->clear($outdated);