Completed
Branch 6.0 (d30585)
by yun
04:17
created

CacheStore   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 92.86%

Importance

Changes 0
Metric Value
dl 0
loc 37
rs 10
c 0
b 0
f 0
ccs 13
cts 14
cp 0.9286
wmc 4
lcom 1
cbo 2

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A save() 0 6 1
A load() 0 8 2
1
<?php
2
// +----------------------------------------------------------------------
3
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
4
// +----------------------------------------------------------------------
5
// | Copyright (c) 2006~2019 http://thinkphp.cn All rights reserved.
6
// +----------------------------------------------------------------------
7
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
8
// +----------------------------------------------------------------------
9
// | Author: yunwuxin <[email protected]>
10
// +----------------------------------------------------------------------
11
declare (strict_types = 1);
12
13
namespace think\filesystem;
14
15
use League\Flysystem\Cached\Storage\AbstractCache;
16
use Psr\SimpleCache\CacheInterface;
17
18
class CacheStore extends AbstractCache
19
{
20
    protected $store;
21
22
    protected $key;
23
24
    protected $expire;
25
26 3
    public function __construct(CacheInterface $store, $key = 'flysystem', $expire = null)
27
    {
28 3
        $this->key    = $key;
29 3
        $this->store  = $store;
30 3
        $this->expire = $expire;
31 3
    }
32
33
    /**
34
     * Store the cache.
35
     */
36 3
    public function save()
37
    {
38 3
        $contents = $this->getForStorage();
39
40 3
        $this->store->set($this->key, $contents, $this->expire);
41 3
    }
42
43
    /**
44
     * Load the cache.
45
     */
46 3
    public function load()
47
    {
48 3
        $contents = $this->store->get($this->key);
49
50 3
        if (!is_null($contents)) {
51
            $this->setFromStorage($contents);
52
        }
53 3
    }
54
}
55