diff --git a/composer.json b/composer.json index 7f47c46..a08843a 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ ], "homepage": "https://github.com/kolirt/laravel-cacheable", "license": "MIT", - "version": "1.0.2", + "version": "1.1.0", "authors": [ { "name": "kolirt" diff --git a/config/cacheable.php b/config/cacheable.php index b4257a4..e85aa7d 100644 --- a/config/cacheable.php +++ b/config/cacheable.php @@ -1,7 +1,14 @@ false, + /* + |-------------------------------------------------------------------------- + | Namespace + |-------------------------------------------------------------------------- + | + | Add namespace class to key cache + */ + 'namespace' => env('CACHEABLE_NAMESPACE', false), /* |-------------------------------------------------------------------------- @@ -11,5 +18,14 @@ | Supported values: int in minutes, "endOfDay", "endOfHour", "endOfMinute", "endOfMonth", "endOfWeek", "endOfYear" | */ - 'cache_time' => 24 * 60 + 'default_cache_time' => env('CACHEABLE_DEFAULT_CACHE_TIME', 24 * 60), + + /* + |-------------------------------------------------------------------------- + | Disable caching + |-------------------------------------------------------------------------- + | + | Disable caching for all + */ + 'disable_cache' => env('CACHEABLE_DISABLE_CACHING', false), ]; diff --git a/src/Traits/Cacheable.php b/src/Traits/Cacheable.php index 5f0ee23..2a738f7 100644 --- a/src/Traits/Cacheable.php +++ b/src/Traits/Cacheable.php @@ -20,7 +20,7 @@ trait Cacheable public function __construct() { - switch (config('cacheable.cache_time')) { + switch (config('cacheable.default_cache_time')) { case 'endOfDay': $this->setCacheTime(now()->endOfDay()); break; @@ -40,7 +40,7 @@ public function __construct() $this->setCacheTime(now()->endOfYear()); break; default: - $this->setCacheTime(now()->addMinutes(config('cacheable.cache_time'))); + $this->setCacheTime(now()->addMinutes(config('cacheable.default_cache_time'))); break; } } @@ -91,7 +91,7 @@ protected function cache(Closure $fnc, ...$args) $cache = Cache::getFacadeRoot(); } - if ($this->cache_disabled) { + if ($this->cache_disabled || config('cacheable.disable_cache')) { return $fnc(); } else { return $cache->remember($data['key'], $this->cache_time, $fnc);