Skip to content

Commit

Permalink
fix(Context): Fix deleting cache in context and drop tags usage by de…
Browse files Browse the repository at this point in the history
…fault

BREAKING CHANGE: Drop default tag for context cache - Laravel offical recommendation is not to use tags with redis
  • Loading branch information
pionl committed Jul 29, 2024
1 parent c2f8bc0 commit d9e2469
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions src/Context/Services/ContextService.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

class ContextService implements ContextServiceContract
{
protected const TAG = 'context';

public function __construct(
private readonly CacheMeServiceContract $cacheMeManager,
private readonly ImplementsService $implementsService
Expand All @@ -31,7 +29,11 @@ public function delete(AbstractContext $context): void
{
$fullCacheKey = $this->getCacheKey($context);

$this->cacheMeManager->delete(key: $fullCacheKey, strategy: $this->cacheStrategy($context));
$this->cacheMeManager->delete(
key: $fullCacheKey,
tags: $this->getTags($context),
strategy: $this->cacheStrategy($context)
);
}

/**
Expand Down Expand Up @@ -99,7 +101,7 @@ protected function cacheStrategy(AbstractContext $context): CacheMeStrategy

protected function getTags(AbstractContext $context): array
{
$tags = [self::TAG];
$tags = [];

if ($this->implementsService->check($context, UseCacheWithTags::class) === false) {
return $tags;
Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/Context/Services/ContextServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function assert(
cacheMeManager: new CacheMeServiceContractAssert(get: [
new CacheMeServiceContractGetExpectation(
key: $expectedCacheKey,
tags: ['context'],
tags: [],
minutes: 3600,
strategy: CacheMeStrategy::Memory,
callGetValueHook: $callHook
Expand Down

0 comments on commit d9e2469

Please sign in to comment.