Skip to content

Commit d179009

Browse files
committed
Resolved #41 set cache adapter
1 parent 34ab03b commit d179009

4 files changed

Lines changed: 13 additions & 4 deletions

File tree

examples/example1/app/Config/fileStorage.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
'web' => $web
7373
],
7474
'cache' => [
75+
'adapter' => 'cache',
7576
'life' => 600 // in seconds
7677
],
7778
'publicUrls' => [

examples/example2/Config/fileStorage.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,12 @@
1313
'local' => $local,
1414
'cache' => $cache,
1515
'web' => $web
16+
],
17+
'cache' => [
18+
'adapter' => 'cache',
19+
'life' => 600 // in seconds
20+
],
21+
'publicUrls' => [
22+
'local' => ''
1623
]
1724
];

src/Image.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function __construct($driver, $config)
7777
{
7878
$this->config = $config;
7979
$adapters = $config['adapters'];
80-
$cache = $config['cache'] ?? ['life' => 600];
80+
$cache = $config['cache'] ?? ['life' => 600, 'adapter' => 'cache'];
8181

8282
$this->cache = $cache;
8383
$this->manager = new MountManager($adapters);
@@ -163,6 +163,7 @@ protected function createCachePath($originalImage, $output = [])
163163
return str_replace($basename, rtrim($originalImage, '.' . $ext), $cache);
164164
}
165165

166+
166167
/**
167168
* @param $adapter
168169
* @param $originalImage
@@ -178,7 +179,7 @@ public function cache($adapter, $originalImage, $default = false)
178179

179180
$cache = $this->createCachePath($originalImage, $output);
180181

181-
$cacheAdapter = 'cache://' . $cache;
182+
$cacheAdapter = $cache['adapter'] ?? 'cache' . '://' . $cache;
182183
$sourceAdapter = $adapter . '://' . $originalImage;
183184

184185
$has = $this->manager->has($cacheAdapter);

src/Storage.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ public function drop($adapter, $file)
141141
*/
142142
if (!empty($get['cache'])) {
143143
foreach ($get['cache'] as $key => $value) {
144-
if ($this->manager->has($adapter . '://' . $value['file_cache_path'])) {
145-
$this->manager->delete($adapter . '://' . $value['file_cache_path']);
144+
if ($this->manager->has($value['file_cache_adapter'] . '://' . $value['file_cache_path'])) {
145+
$this->manager->delete($value['file_cache_adapter'] . '://' . $value['file_cache_path']);
146146
}
147147
}
148148
}

0 commit comments

Comments
 (0)