3 * @file src/Core/Cache.php
5 namespace Friendica\Core;
7 use Friendica\BaseObject;
8 use Friendica\Core\Cache\ICacheDriver;
11 * @brief Class for storing data for a short time
13 class Cache extends BaseObject
15 /** @deprecated Use ICacheDriver::MONTH */
16 const MONTH = ICacheDriver::MONTH;
17 /** @deprecated Use ICacheDriver::WEEK */
19 /** @deprecated Use ICacheDriver::DAY */
21 /** @deprecated Use ICacheDriver::HOUR */
23 /** @deprecated Use ICacheDriver::HALF_HOUR */
24 const HALF_HOUR = 1800;
25 /** @deprecated Use ICacheDriver::QUARTER_HOUR */
26 const QUARTER_HOUR = 900;
27 /** @deprecated Use ICacheDriver::FIVE_MINUTES */
28 const FIVE_MINUTES = 300;
29 /** @deprecated Use ICacheDriver::MINUTE */
31 /** @deprecated Use ICacheDriver::INFINITE */
35 * @brief Returns all the cache keys sorted alphabetically
37 * @param string $prefix Prefix of the keys (optional)
39 * @return array Empty if the driver doesn't support this feature
42 public static function getAllKeys($prefix = null)
44 return self::getClass(ICacheDriver::class)->getAllKeys($prefix);
48 * @brief Fetch cached data according to the key
50 * @param string $key The key to the cached data
52 * @return mixed Cached $value or "null" if not found
55 public static function get($key)
57 return self::getClass(ICacheDriver::class)->get($key);
61 * @brief Put data in the cache according to the key
63 * The input $value can have multiple formats.
65 * @param string $key The key to the cached data
66 * @param mixed $value The value that is about to be stored
67 * @param integer $duration The cache lifespan
72 public static function set($key, $value, $duration = ICacheDriver::MONTH)
74 return self::getClass(ICacheDriver::class)->set($key, $value, $duration);
78 * @brief Delete a value from the cache
80 * @param string $key The key to the cached data
85 public static function delete($key)
87 return self::getClass(ICacheDriver::class)->delete($key);
91 * @brief Remove outdated data from the cache
93 * @param boolean $outdated just remove outdated values
98 public static function clear($outdated = true)
100 return self::getClass(ICacheDriver::class)->clear($outdated);