Completed
Push — master ( afe80a...325e9f )
by Marin
07:33
created

CacheInvalidator   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 50
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A invalidateByModel() 0 5 1
A invalidateByTags() 0 4 1
A invalidateByKeys() 0 6 2
1
<?php
2
3
namespace Anorgan\LaravelCache;
4
5
use AlternativeLaravelCache\Core\AlternativeCacheStore;
6
use Illuminate\Database\Eloquent\Model;
7
8
/**
9
 * Class CacheInvalidator
10
 * @package Anorgan\LaravelCache
11
 */
12
class CacheInvalidator
13
{
14
    /**
15
     * @var AlternativeCacheStore
16
     */
17
    private $cacheStore;
18
19
    /**
20
     * @var TagFinder
21
     */
22
    protected $tagFinder;
23
24
    /**
25
     * CacheInvalidator constructor.
26
     * @param AlternativeCacheStore $cacheStore
27
     * @param TagFinder $tagFinder
28
     */
29
    public function __construct(AlternativeCacheStore $cacheStore, TagFinder $tagFinder)
30
    {
31
        $this->tagFinder = $tagFinder;
32
        $this->cacheStore = $cacheStore;
33
    }
34
35
    /**
36
     * @param Model $model
37
     */
38
    public function invalidateByModel(Model $model)
39
    {
40
        $tags = $this->tagFinder->find($model);
41
        $this->invalidateByTags($tags);
42
    }
43
44
    /**
45
     * @param array $tags
46
     */
47
    public function invalidateByTags(array $tags)
48
    {
49
        $this->cacheStore->tags($tags)->flush();
50
    }
51
52
    /**
53
     * @param array $keys
54
     */
55
    public function invalidateByKeys(array $keys)
56
    {
57
        foreach ($keys as $key) {
58
            $this->cacheStore->forget($key);
59
        }
60
    }
61
}
62