Skip to content

Commit

Permalink
change cache_time config to default_cache_time; add global disable ca…
Browse files Browse the repository at this point in the history
…ching
  • Loading branch information
kolirt committed Sep 26, 2024
1 parent 7c10ef5 commit 4f8c124
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
],
"homepage": "https://github.com/kolirt/laravel-cacheable",
"license": "MIT",
"version": "1.0.2",
"version": "1.1.0",
"authors": [
{
"name": "kolirt"
Expand Down
20 changes: 18 additions & 2 deletions config/cacheable.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
<?php

return [
'namespace' => false,
/*
|--------------------------------------------------------------------------
| Namespace
|--------------------------------------------------------------------------
|
| Add namespace class to key cache
*/
'namespace' => env('CACHEABLE_NAMESPACE', false),

/*
|--------------------------------------------------------------------------
Expand All @@ -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),
];
6 changes: 3 additions & 3 deletions src/Traits/Cacheable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 4f8c124

Please sign in to comment.