Skip to content

Commit

Permalink
add caching time variations
Browse files Browse the repository at this point in the history
  • Loading branch information
kolirt committed Sep 10, 2024
1 parent 7fce70e commit a2fc2bd
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 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.0",
"version": "1.0.1",
"authors": [
{
"name": "kolirt"
Expand Down
10 changes: 9 additions & 1 deletion config/cacheable.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,13 @@
return [
'namespace' => false,

'cache_time' => 24 * 60, // minutes
/*
|--------------------------------------------------------------------------
| Caching time
|--------------------------------------------------------------------------
|
| Supported values: int in minutes, "endOfDay", "endOfHour", "endOfMinute", "endOfMonth", "endOfWeek", "endOfYear"
|
*/
'cache_time' => 24 * 60
];
24 changes: 23 additions & 1 deletion src/Traits/Cacheable.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,29 @@ trait Cacheable

public function __construct()
{
$this->setCacheTime(now()->addMinutes(config('cacheable.cache_time')));
switch (config('cacheable.cache_time')) {
case 'endOfDay':
$this->setCacheTime(now()->endOfDay());
break;
case 'endOfHour':
$this->setCacheTime(now()->endOfHour());
break;
case 'endOfMinute':
$this->setCacheTime(now()->endOfMinute());
break;
case 'endOfMonth':
$this->setCacheTime(now()->endOfMonth());
break;
case 'endOfWeek':
$this->setCacheTime(now()->endOfWeek());
break;
case 'endOfYear':
$this->setCacheTime(now()->endOfYear());
break;
default:
$this->setCacheTime(now()->addMinutes(config('cacheable.cache_time')));
break;
}
}

public function appendCacheTags(array $tags): self
Expand Down

0 comments on commit a2fc2bd

Please sign in to comment.