Skip to content

[BUG] Cache invalidation because of pattern matching never happens in RedisStorage #26

@Valentina-Gol

Description

@Valentina-Gol

Describe the bug
Cache invalidation because of patter matching never happens in RedisStorage

To Reproduce
Steps to reproduce the behavior:

  1. Setup cache middlware with Redis storage, add CacheDropConfig with some invalidation pattern matched the route
  2. Fill the cache, by requesting GET-routes matched the invalidation pattern
  3. Invalidate cache by using POST/PUT?PATCH-routes, macthed the invalidation pattern
  4. See "The search did not find any matches"

Expected behavior
In InMemoryStorage we use filtering by value to collect keys to delete. It allows to compare invalidation pattern and route.

# Find all keys matching path pattern
keys_to_remove = []
for key, (_, request, _) in self._storage.items():
    if path.match(request.url.path):
        keys_to_remove.append(key)

In RedisStorage we filters raw keys which are hashed values and don't contain any routes paths.

pattern = self._full_key(str(raw.rstrip("$") + "/*"))
logger.debug(f"Removing key: %s", pattern)

result = await self._storage.scan(match=pattern)

Environment:

  • OS: Windows 10
  • Python version: 3.11.0
  • FastCacheMiddleware version: 0.0.6

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions