Skip to content

Commit

Permalink
Discard old test changes
Browse files Browse the repository at this point in the history
  • Loading branch information
alloylab committed Jan 4, 2025
1 parent c25d879 commit 821ad37
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
9 changes: 9 additions & 0 deletions src/Components/SetUp/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ final class Cache implements Wireable

public bool $enabled = true;

public string $tag = '';

public int $ttl = 300;

public string $prefix = '';
Expand All @@ -21,6 +23,13 @@ public function disabled(): Cache
return $this;
}

public function customTag(string $tag): Cache
{
$this->tag = $tag;

return $this;
}

public function prefix(string $prefix): Cache
{
$this->prefix = $prefix;
Expand Down
10 changes: 6 additions & 4 deletions src/PowerGridComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ protected function getRecords(): mixed
return collect();
}

if (boolval(data_get($this->setUp, 'cache.enabled'))) {
if (boolval(data_get($this->setUp, 'cache.enabled')) && Cache::supportsTags()) {
return $this->getRecordsFromCache();
}

Expand All @@ -137,12 +137,14 @@ protected function getRecords(): mixed

private function getRecordsFromCache(): mixed
{
$prefix = 'powergrid_' . strval(data_get($this->setUp, 'cache.prefix'));
$prefix = strval(data_get($this->setUp, 'cache.prefix'));
$customTag = strval(data_get($this->setUp, 'cache.tag'));
$ttl = intval(data_get($this->setUp, 'cache.ttl'));

$cacheKey = $prefix . '_' . implode('-', $this->getCacheKeys());
$tag = $prefix . ($customTag ?: 'powergrid-' . $this->datasource()->getModel()->getTable() . '-' . $this->tableName);
$cacheKey = implode('-', $this->getCacheKeys());

$results = Cache::remember($cacheKey, $ttl, fn () => ProcessDataSource::make($this)->get());
$results = Cache::tags($tag)->remember($cacheKey, $ttl, fn () => ProcessDataSource::make($this)->get());

if ($this->measurePerformance) {
app(Dispatcher::class)->dispatch(
Expand Down

0 comments on commit 821ad37

Please sign in to comment.