]> git.mxchange.org Git - friendica.git/blob - src/Core/Cache.php
Merge pull request #7465 from nupplaphil/task/dice_cache_lock
[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\Cache as CacheClass;
9 use Friendica\Core\Cache\ICache;
10
11 /**
12  * @brief Class for storing data for a short time
13  */
14 class Cache extends BaseObject
15 {
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;
34
35         /**
36          * @brief Returns all the cache keys sorted alphabetically
37          *
38          * @param string $prefix Prefix of the keys (optional)
39          *
40          * @return array Empty if the driver doesn't support this feature
41          * @throws \Exception
42          */
43         public static function getAllKeys($prefix = null)
44         {
45                 return self::getClass(ICache::class)->getAllKeys($prefix);
46         }
47
48         /**
49          * @brief Fetch cached data according to the key
50          *
51          * @param string $key The key to the cached data
52          *
53          * @return mixed Cached $value or "null" if not found
54          * @throws \Exception
55          */
56         public static function get($key)
57         {
58                 return self::getClass(ICache::class)->get($key);
59         }
60
61         /**
62          * @brief Put data in the cache according to the key
63          *
64          * The input $value can have multiple formats.
65          *
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
69          *
70          * @return bool
71          * @throws \Exception
72          */
73         public static function set($key, $value, $duration = CacheClass::MONTH)
74         {
75                 return self::getClass(ICache::class)->set($key, $value, $duration);
76         }
77
78         /**
79          * @brief Delete a value from the cache
80          *
81          * @param string $key The key to the cached data
82          *
83          * @return bool
84          * @throws \Exception
85          */
86         public static function delete($key)
87         {
88                 return self::getClass(ICache::class)->delete($key);
89         }
90
91         /**
92          * @brief Remove outdated data from the cache
93          *
94          * @param boolean $outdated just remove outdated values
95          *
96          * @return bool
97          * @throws \Exception
98          */
99         public static function clear($outdated = true)
100         {
101                 return self::getClass(ICache::class)->clear($outdated);
102         }
103 }