File tree Expand file tree Collapse file tree 1 file changed +64
-0
lines changed Expand file tree Collapse file tree 1 file changed +64
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments