summaryrefslogtreecommitdiff
path: root/app/Core/Cache/BaseCache.php
blob: 04f8d22060dcb45da559c0c1be8a3ce7ecf41c47 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php

namespace Kanboard\Core\Cache;

/**
 * Base Class for Cache Drivers
 *
 * @package  Kanboard\Core\Cache
 * @author   Frederic Guillot
 */
abstract class BaseCache
{
    /**
     * Store an item in the cache
     *
     * @access public
     * @param  string  $key
     * @param  string  $value
     */
    abstract public function set($key, $value);

    /**
     * Retrieve an item from the cache by key
     *
     * @access public
     * @param  string  $key
     * @return mixed            Null when not found, cached value otherwise
     */
    abstract public function get($key);

    /**
     * Remove all items from the cache
     *
     * @access public
     */
    abstract public function flush();

    /**
     * Remove an item from the cache
     *
     * @access public
     * @param  string  $key
     */
    abstract public function remove($key);

    /**
     * Proxy cache
     *
     * Note: Arguments must be scalar types
     *
     * @access public
     * @param  string    $class        Class instance
     * @param  string    $method       Container method
     * @return mixed
     */
    public function proxy($class, $method)
    {
        $args = func_get_args();
        array_shift($args);

        $key = 'proxy:'.get_class($class).':'.implode(':', $args);
        $result = $this->get($key);

        if ($result === null) {
            $result = call_user_func_array(array($class, $method), array_splice($args, 1));
            $this->set($key, $result);
        }

        return $result;
    }
}