CacheRuntime   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
dl 0
loc 51
rs 10
c 0
b 0
f 0

5 Methods

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