Completed
Pull Request — master (#78)
by Franco
01:37
created

CacheAfterCallAspect   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 15
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A afterCall() 0 7 3
1
<?php
2
3
namespace LeKoala\DebugBar\Aspect;
4
5
use Psr\SimpleCache\CacheInterface;
6
use SilverStripe\Core\Injector\AfterCallAspect;
7
use SilverStripe\Core\Injector\Injector;
8
9
class CacheAfterCallAspect implements AfterCallAspect
10
{
11
    /**
12
     * Logs all hits/misses after a CacheInterface::get call is made.
13
     *
14
     * {@inheritdoc}
15
     */
16
    public function afterCall($proxied, $method, $args, $result)
17
    {
18
        $message = (empty($result)) ? "Missed: {$args[0]}" : "Hit: {$args[0]}";
19
        if ($cache = Injector::inst()->get(CacheInterface::class . '.backend')) {
20
            $cache->templateCache[$message] = array('cache_result' => array('result' => $result));
21
        }
22
    }
23
}
24