1 | <?php |
||
10 | class TextCacheItemPool implements CacheItemPoolInterface { |
||
11 | /** @var array **/ |
||
12 | protected $deferredItems; |
||
13 | /** @var string **/ |
||
14 | protected $cacheFolder; |
||
15 | |||
16 | /** |
||
17 | * @param array $options |
||
18 | */ |
||
19 | 10 | public function __construct($options = []) { |
|
22 | |||
23 | /** |
||
24 | * @param array $options |
||
25 | */ |
||
26 | 10 | protected function configure($options) { |
|
27 | 10 | $this->cacheFolder = |
|
28 | 10 | (isset($options['cache_folder'])) |
|
29 | 10 | ? "{$options['cache_folder']}/text" |
|
30 | : __DIR__ . '/../../../data/cache/text' |
||
31 | ; |
||
32 | 10 | } |
|
33 | |||
34 | /** |
||
35 | * {@inheritdoc} |
||
36 | */ |
||
37 | 2 | public function deleteItem($key) { |
|
38 | 2 | if(is_file("{$this->cacheFolder}/$key.txt")) { |
|
|
|||
39 | 2 | unlink("{$this->cacheFolder}/$key.txt"); |
|
40 | } |
||
41 | 2 | if(isset($this->deferredItems[$key])) { |
|
42 | unset($this->deferredItems[$key]); |
||
43 | } |
||
44 | 2 | return true; |
|
45 | } |
||
46 | |||
47 | /** |
||
48 | * {@inheritdoc} |
||
49 | */ |
||
50 | 1 | public function deleteItems(array $keys) { |
|
51 | 1 | foreach($keys as $key) { |
|
52 | 1 | if(!$this->deleteItem($key)) { |
|
53 | 1 | return false; |
|
54 | } |
||
55 | } |
||
56 | 1 | return true; |
|
57 | } |
||
58 | |||
59 | /** |
||
60 | * {@inheritdoc} |
||
61 | */ |
||
62 | 9 | public function save(CacheItemInterface $item) { |
|
69 | |||
70 | /** |
||
71 | * {@inheritdoc} |
||
72 | */ |
||
73 | 2 | public function saveDeferred(CacheItemInterface $item) { |
|
78 | |||
79 | /** |
||
80 | * {@inheritdoc} |
||
81 | */ |
||
82 | 2 | public function commit() { |
|
83 | 2 | foreach($this->deferredItems as $key => $item) { |
|
84 | 2 | $this->save($item); |
|
85 | 2 | unset($this->deferredItems[$key]); |
|
86 | } |
||
87 | 2 | return true; |
|
88 | } |
||
89 | |||
90 | /** |
||
91 | * {@inheritdoc} |
||
92 | */ |
||
93 | 10 | public function hasItem($key) { |
|
96 | |||
97 | /** |
||
98 | * {@inheritdoc} |
||
99 | */ |
||
100 | 6 | public function getItem($key) { |
|
111 | |||
112 | /** |
||
113 | * {@inheritdoc} |
||
114 | */ |
||
115 | 2 | public function getItems(array $keys = array()) { |
|
124 | |||
125 | /** |
||
126 | * {@inheritdoc} |
||
127 | */ |
||
128 | 10 | public function clear() { |
|
137 | } |
||
138 |