]> git.mxchange.org Git - friendica.git/blob - src/Core/Cache.php
Rename *CacheDriver to *Cache because they don't act as driver anymore
[friendica.git] / src / Core / Cache.php
1 <?php
2 /**
3  * @file src/Core/Cache.php
4  */
5 namespace Friendica\Core;
6
7 use Friendica\BaseObject;
8 use Friendica\Core\Cache\ICache;
9
10 /**
11  * @brief Class for storing data for a short time
12  */
13 class Cache extends BaseObject
14 {
15         /** @deprecated Use ICache::MONTH */
16         const MONTH        = ICache::MONTH;
17         /** @deprecated Use ICache::WEEK */
18         const WEEK         = ICache::WEEK;
19         /** @deprecated Use ICache::DAY */
20         const DAY          = ICache::DAY;
21         /** @deprecated Use ICache::HOUR */
22         const HOUR         = ICache::HOUR;
23         /** @deprecated Use ICache::HALF_HOUR */
24         const HALF_HOUR    = ICache::HALF_HOUR;
25         /** @deprecated Use ICache::QUARTER_HOUR */
26         const QUARTER_HOUR = ICache::QUARTER_HOUR;
27         /** @deprecated Use ICache::FIVE_MINUTES */
28         const FIVE_MINUTES = ICache::FIVE_MINUTES;
29         /** @deprecated Use ICache::MINUTE */
30         const MINUTE       = ICache::MINUTE;
31         /** @deprecated Use ICache::INFINITE */
32         const INFINITE     = ICache::INFINITE;
33
34         /**
35          * @brief Returns all the cache keys sorted alphabetically
36          *
37          * @param string $prefix Prefix of the keys (optional)
38          *
39          * @return array Empty if the driver doesn't support this feature
40          * @throws \Exception
41          */
42         public static function getAllKeys($prefix = null)
43         {
44                 return self::getClass(ICache::class)->getAllKeys($prefix);
45         }
46
47         /**
48          * @brief Fetch cached data according to the key
49          *
50          * @param string $key The key to the cached data
51          *
52          * @return mixed Cached $value or "null" if not found
53          * @throws \Exception
54          */
55         public static function get($key)
56         {
57                 return self::getClass(ICache::class)->get($key);
58         }
59
60         /**
61          * @brief Put data in the cache according to the key
62          *
63          * The input $value can have multiple formats.
64          *
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
68          *
69          * @return bool
70          * @throws \Exception
71          */
72         public static function set($key, $value, $duration = ICache::MONTH)
73         {
74                 return self::getClass(ICache::class)->set($key, $value, $duration);
75         }
76
77         /**
78          * @brief Delete a value from the cache
79          *
80          * @param string $key The key to the cached data
81          *
82          * @return bool
83          * @throws \Exception
84          */
85         public static function delete($key)
86         {
87                 return self::getClass(ICache::class)->delete($key);
88         }
89
90         /**
91          * @brief Remove outdated data from the cache
92          *
93          * @param boolean $outdated just remove outdated values
94          *
95          * @return bool
96          * @throws \Exception
97          */
98         public static function clear($outdated = true)
99         {
100                 return self::getClass(ICache::class)->clear($outdated);
101         }
102 }