Completed
Push — master ( 168d9f...7069c0 )
by Marin
01:38
created

AlternativeRedisCacheStore   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 0
dl 0
loc 30
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A rememberWithTags() 0 21 4
1
<?php
2
3
namespace Anorgan\LaravelCache;
4
5
use \AlternativeLaravelCache\Store\AlternativeRedisCacheStore as BaseAlternativeRedisCacheStore;
6
use Illuminate\Database\Eloquent\Model;
7
use Illuminate\Support\Collection;
8
9
class AlternativeRedisCacheStore extends BaseAlternativeRedisCacheStore
10
{
11
    /**
12
     * @param $key
13
     * @param $minutes
14
     * @param Closure $callback
15
     * @param array $tags
16
     */
17
    public function rememberWithTags($key, $minutes, \Closure $callback, array $tags = [])
18
    {
19
        // If the item exists in the cache we will just return this immediately
20
        // otherwise we will execute the given Closure and cache the result
21
        // of that execution for the given number of minutes in storage.
22
        if (! is_null($value = $this->get($key))) {
23
            return $value;
24
        }
25
26
        $value = $callback();
27
28
        if ($value instanceof Collection || $value instanceof Model) {
29
            $tags  = array_merge(app(TagFinder::class)->find($value), $tags);
30
        }
31
32
        $this
33
            ->tags($tags)
34
            ->put($key, $value, $minutes);
35
36
        return $value;
37
    }
38
}
39