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

CacheStore::load()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 8
rs 10
c 0
b 0
f 0
ccs 4
cts 5
cp 0.8
crap 2.032
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