]> git.mxchange.org Git - friendica.git/blob - src/Core/Cache.php
Move Cache::clear() to DI::cache()->clear()
[friendica.git] / src / Core / Cache.php
1 <?php
2 /**
3  * @file src/Core/Cache.php
4  */
5 namespace Friendica\Core;
6
7 use Friendica\Core\Cache\Cache as CacheClass;
8 use Friendica\DI;
9
10 /**
11  * @brief Class for storing data for a short time
12  */
13 class Cache
14 {
15         /** @deprecated Use CacheClass::MONTH */
16         const MONTH        = CacheClass::MONTH;
17         /** @deprecated Use CacheClass::WEEK */
18         const WEEK         = CacheClass::WEEK;
19         /** @deprecated Use CacheClass::DAY */
20         const DAY          = CacheClass::DAY;
21         /** @deprecated Use CacheClass::HOUR */
22         const HOUR         = CacheClass::HOUR;
23         /** @deprecated Use CacheClass::HALF_HOUR */
24         const HALF_HOUR    = CacheClass::HALF_HOUR;
25         /** @deprecated Use CacheClass::QUARTER_HOUR */
26         const QUARTER_HOUR = CacheClass::QUARTER_HOUR;
27         /** @deprecated Use CacheClass::FIVE_MINUTES */
28         const FIVE_MINUTES = CacheClass::FIVE_MINUTES;
29         /** @deprecated Use CacheClass::MINUTE */
30         const MINUTE       = CacheClass::MINUTE;
31         /** @deprecated Use CacheClass::INFINITE */
32         const INFINITE     = CacheClass::INFINITE;
33
34         /**
35          * @brief Fetch cached data according to the key
36          *
37          * @param string $key The key to the cached data
38          *
39          * @return mixed Cached $value or "null" if not found
40          * @throws \Exception
41          */
42         public static function get($key)
43         {
44                 return DI::cache()->get($key);
45         }
46
47         /**
48          * @brief Put data in the cache according to the key
49          *
50          * The input $value can have multiple formats.
51          *
52          * @param string  $key      The key to the cached data
53          * @param mixed   $value    The value that is about to be stored
54          * @param integer $duration The cache lifespan
55          *
56          * @return bool
57          * @throws \Exception
58          */
59         public static function set($key, $value, $duration = CacheClass::MONTH)
60         {
61                 return DI::cache()->set($key, $value, $duration);
62         }
63
64         /**
65          * @brief Delete a value from the cache
66          *
67          * @param string $key The key to the cached data
68          *
69          * @return bool
70          * @throws \Exception
71          */
72         public static function delete($key)
73         {
74                 return DI::cache()->delete($key);
75         }
76 }