Skip to content

Commit

Permalink
[1.x] Add possibility to change cache duration (#113)
Browse files Browse the repository at this point in the history
* Add possibility to change cache duration

* Support wider types to match underlying remember types

---------

Co-authored-by: Tim MacDonald <[email protected]>
  • Loading branch information
pierrepavlov and timacdonald authored Dec 4, 2023
1 parent 6d27eed commit 37f6439
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Livewire/Concerns/RemembersQueries.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

use Carbon\CarbonImmutable;
use Carbon\CarbonInterval;
use Closure;
use DateInterval;
use DateTimeInterface;
use Illuminate\Support\Benchmark;
use Illuminate\Support\Facades\App;
use Laravel\Pulse\Support\CacheStoreResolver;
Expand All @@ -15,9 +18,9 @@ trait RemembersQueries
*
* @return array{0: mixed, 1: float, 2: string}
*/
public function remember(callable $query, string $key = ''): array
public function remember(callable $query, string $key = '', DateTimeInterface|DateInterval|Closure|int|null $ttl = 5): array
{
return App::make(CacheStoreResolver::class)->store()->remember('laravel:pulse:'.static::class.':'.$key.':'.$this->period, CarbonInterval::seconds(5), function () use ($query) {
return App::make(CacheStoreResolver::class)->store()->remember('laravel:pulse:'.static::class.':'.$key.':'.$this->period, $ttl, function () use ($query) {
$start = CarbonImmutable::now()->toDateTimeString();

[$value, $duration] = Benchmark::value(fn () => $query($this->periodAsInterval()));
Expand Down

0 comments on commit 37f6439

Please sign in to comment.