InteractsWithCache   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 45
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getCache() 0 7 2
A setCache() 0 5 1
A createDefaultCache() 0 3 1
1
<?php
2
3
/*
4
 * This file is part of the strays/baidu-ai.
5
 *
6
 * (c) strays <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Strays\BaiDuAi\Kernel\Traits;
13
14
use Symfony\Component\Cache\Simple\FilesystemCache;
15
16
trait InteractsWithCache
17
{
18
    /**
19
     * 缓存实例.
20
     *
21
     * @var
22
     */
23
    protected $cache;
24
25
    /**
26
     * 获取缓存.
27
     *
28
     * @return FilesystemCache
29
     */
30
    public function getCache()
31
    {
32
        if ($this->cache) {
33
            return $this->cache;
34
        }
35
36
        return $this->cache = $this->createDefaultCache();
37
    }
38
39
    /**
40
     * 设置缓存.
41
     *
42
     * @param $cache
43
     *
44
     * @return $this
45
     */
46
    public function setCache($cache)
47
    {
48
        $this->cache = $cache;
49
50
        return $this;
51
    }
52
53
    /**
54
     * 创建默认缓存.
55
     *
56
     * @return FilesystemCache
57
     */
58
    public function createDefaultCache()
59
    {
60
        return new FilesystemCache();
61
    }
62
}
63