Completed
Push — master ( 3c1969...5b5792 )
by Schlaefer
03:16 queued 10s
created

CacheSupportComponent::_addConfigureCachelets()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 0
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
1
<?php
2
3
namespace App\Controller\Component;
4
5
use Cake\Controller\Component;
6
use Cake\Core\App;
7
use Cake\Core\Configure;
8
use Cake\Event\Event;
9
use Saito\Cache\CacheSupport;
10
use Saito\Cache\ItemCache;
11
use Saito\Cache\LineCacheSupportCachelet;
12
use Saito\Cache\SaitoCacheEngineAppCache;
13
14
class CacheSupportComponent extends Component
15
{
16
17
    protected $_CacheSupport;
18
19
    /**
20
     * @var ItemCache
21
     */
22
    public $LineCache;
23
24
    /**
25
     * {@inheritDoc}
26
     */
27
    public function initialize(array $config)
28
    {
29
        $this->_CacheSupport = new CacheSupport();
30
        $this->_initLineCache();
31
    }
32
33
    /**
34
     * Initialize line-cache.
35
     *
36
     * @return void
37
     */
38
    protected function _initLineCache()
39
    {
40
        $this->LineCache = new ItemCache(
41
            'Saito.LineCache',
42
            new SaitoCacheEngineAppCache,
43
            // duration: update relative time values in HTML at least every hour
44
            ['duration' => 3600, 'maxItems' => 600]
45
        );
46
        $this->_CacheSupport->add(
47
            new LineCacheSupportCachelet($this->LineCache)
48
        );
49
    }
50
51
    /**
52
     * {@inheritDoc}
53
     */
54
    public function beforeRender(Event $event)
55
    {
56
        $event->getSubject()->set('LineCache', $this->LineCache);
57
    }
58
59
    /**
60
     * {@inheritDoc}
61
     */
62
    public function __call($method, $params)
63
    {
64
        $proxy = [$this->_CacheSupport, $method];
65
        if (is_callable($proxy)) {
66
            return call_user_func_array($proxy, $params);
67
        }
68
    }
69
}
70