Psr6Cache::save()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1.0028

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 6
cts 7
cp 0.8571
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1.0028
1
<?php
2
3
namespace League\Flysystem\Cached\Storage;
4
5
use Psr\Cache\CacheItemPoolInterface;
6
7
class Psr6Cache extends AbstractCache
8
{
9
    /**
10
     * @var CacheItemPoolInterface
11
     */
12
    private $pool;
13
14
    /**
15
     * @var string storage key
16
     */
17
    protected $key;
18
19
    /**
20
     * @var int|null seconds until cache expiration
21
     */
22
    protected $expire;
23
24
    /**
25
     * Constructor.
26
     *
27
     * @param CacheItemPoolInterface $pool
28
     * @param string                 $key    storage key
29
     * @param int|null               $expire seconds until cache expiration
30
     */
31 9
    public function __construct(CacheItemPoolInterface $pool, $key = 'flysystem', $expire = null)
32
    {
33 9
        $this->pool = $pool;
34 9
        $this->key = $key;
35 9
        $this->expire = $expire;
36 9
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41 3
    public function save()
42
    {
43 3
        $item = $this->pool->getItem($this->key);
44 3
        $item->set($this->getForStorage());
45 3
        $item->expiresAfter($this->expire);
46 3
        $this->pool->save($item);
47 3
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52 6
    public function load()
53
    {
54 6
        $item = $this->pool->getItem($this->key);
55 6
        if ($item->isHit()) {
56 3
            $this->setFromStorage($item->get());
57 3
        }
58
    }
59
}