Completed
Push — master ( 0310b8...c0fca1 )
by Maxim
02:36
created

CacheRuntime::clear()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
1
<?php
2
3
namespace WebComplete\core\utils\cache;
4
5
class CacheRuntime
6
{
7
    protected static $cache = [];
8
9
    /**
10
     * @param string $key
11
     *
12
     * @return mixed|null
13
     */
14
    public static function get(string $key)
15
    {
16
        return self::$cache[$key] ?? null;
17
    }
18
19
    /**
20
     * @param string $key
21
     * @param $value
22
     */
23
    public static function set(string $key, $value)
24
    {
25
        self::$cache[$key] = $value;
26
    }
27
28
    /**
29
     * @param string $key
30
     * @param \Closure $closure
31
     *
32
     * @return mixed
33
     */
34
    public static function getOrSet(string $key, \Closure $closure)
35
    {
36
        if (!isset(self::$cache[$key])) {
37
            self::$cache[$key] = $closure();
38
        }
39
        return self::$cache[$key];
40
    }
41
42
    /**
43
     * @param string $key
44
     */
45
    public static function invalidate(string $key)
46
    {
47
        unset(self::$cache[$key]);
48
    }
49
50
    /**
51
     */
52
    public static function clear()
53
    {
54
        self::$cache = [];
55
    }
56
}
57