Skip to content

Commit 5145166

Browse files
committed
Added YiiCache adapter
1 parent 62cc95a commit 5145166

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

src/YiiCache.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
/**
3+
* @link https://github.com/creocoder/yii2-flysystem
4+
* @copyright Copyright (c) 2015 Alexander Kochetov
5+
* @license http://opensource.org/licenses/BSD-3-Clause
6+
*/
7+
8+
namespace creocoder\flysystem;
9+
10+
use League\Flysystem\Cached\Storage\AbstractCache;
11+
use yii\caching\Cache;
12+
13+
/**
14+
* YiiCache
15+
*
16+
* @author Alexander Kochetov <[email protected]>
17+
*/
18+
class YiiCache extends AbstractCache
19+
{
20+
/**
21+
* @var Cache
22+
*/
23+
protected $yiiCache;
24+
/**
25+
* @var string
26+
*/
27+
protected $key;
28+
/**
29+
* @var integer
30+
*/
31+
protected $duration;
32+
33+
/**
34+
* @param Cache $yiiCache
35+
* @param string $key
36+
* @param integer $duration
37+
*/
38+
public function __construct(Cache $yiiCache, $key = 'flysystem', $duration = 0)
39+
{
40+
$this->yiiCache = $yiiCache;
41+
$this->key = $key;
42+
$this->duration = $duration;
43+
}
44+
45+
/**
46+
* @inheritdoc
47+
*/
48+
public function load()
49+
{
50+
$contents = $this->yiiCache->get($this->key);
51+
52+
if ($contents !== false) {
53+
$this->setFromStorage($contents);
54+
}
55+
}
56+
57+
/**
58+
* @inheritdoc
59+
*/
60+
public function save()
61+
{
62+
$this->yiiCache->set($this->key, $this->getForStorage(), $this->duration);
63+
}
64+
}

0 commit comments

Comments
 (0)