Skip to content

Commit

Permalink
Resolved #41 set cache adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
dusta committed Sep 8, 2022
1 parent 34ab03b commit d179009
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions examples/example1/app/Config/fileStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
'web' => $web
],
'cache' => [
'adapter' => 'cache',
'life' => 600 // in seconds
],
'publicUrls' => [
Expand Down
7 changes: 7 additions & 0 deletions examples/example2/Config/fileStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,12 @@
'local' => $local,
'cache' => $cache,
'web' => $web
],
'cache' => [
'adapter' => 'cache',
'life' => 600 // in seconds
],
'publicUrls' => [
'local' => ''
]
];
5 changes: 3 additions & 2 deletions src/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function __construct($driver, $config)
{
$this->config = $config;
$adapters = $config['adapters'];
$cache = $config['cache'] ?? ['life' => 600];
$cache = $config['cache'] ?? ['life' => 600, 'adapter' => 'cache'];

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


/**
* @param $adapter
* @param $originalImage
Expand All @@ -178,7 +179,7 @@ public function cache($adapter, $originalImage, $default = false)

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

$cacheAdapter = 'cache://' . $cache;
$cacheAdapter = $cache['adapter'] ?? 'cache' . '://' . $cache;
$sourceAdapter = $adapter . '://' . $originalImage;

$has = $this->manager->has($cacheAdapter);
Expand Down
4 changes: 2 additions & 2 deletions src/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ public function drop($adapter, $file)
*/
if (!empty($get['cache'])) {
foreach ($get['cache'] as $key => $value) {
if ($this->manager->has($adapter . '://' . $value['file_cache_path'])) {
$this->manager->delete($adapter . '://' . $value['file_cache_path']);
if ($this->manager->has($value['file_cache_adapter'] . '://' . $value['file_cache_path'])) {
$this->manager->delete($value['file_cache_adapter'] . '://' . $value['file_cache_path']);
}
}
}
Expand Down

0 comments on commit d179009

Please sign in to comment.