Skip to content

Commit

Permalink
Merge pull request #40 from kingyyy/patch-1
Browse files Browse the repository at this point in the history
fix(CacheableQueryBuilder): remove expired items from tagged cache
  • Loading branch information
nea authored Oct 17, 2024
2 parents 9d6182a + 03304ba commit ea21c07
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Database/Query/CacheableQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace ElipZis\Cacheable\Database\Query;

use Illuminate\Cache\RedisTaggedCache;
use Illuminate\Cache\TaggableStore;
use Illuminate\Database\Connection;
use Illuminate\Database\Query\Builder;
Expand Down Expand Up @@ -136,6 +137,11 @@ protected function runSelect()
//and create additional identifiers
$modelClasses = $this->getIdentifiableModelClasses($this->getIdentifiableValue());

// clear expired cached queries in tagged cache
if ($isTaggableStore && Cache::tags($modelClasses) instanceof RedisTaggedCache) {
Cache::tags($modelClasses)->flushStale();
}

//If cached, return
if (($isTaggableStore && Cache::tags($modelClasses)->has($cacheKey)) || Cache::has($cacheKey)) {
$this->log("Found cache entry for '{$cacheKey}'");
Expand Down

0 comments on commit ea21c07

Please sign in to comment.