Closed shijo-keyvalue closed 8 months ago
Hi @shijo-keyvalue
1) that is a bug with tags "templating" - fix is on the way 2) LGFM but just wondering why do you need to write this custom api cache decorator? Can you share a code of extract_client_id?
Hi @Krukov Thanks for the quick response. Appreciate it.
Is there any workaround for this issue. Currently I am catching TagNotRegisteredError and deleting cache entry from redis directly (as cache entry with given key is getting added to redis , even if exception is thrown)
We wanted bit more control on caching. For example - (a) we wanted to bypass and clear cache when a specific request header is present or specific key is present in redis cache. (b) Also we had requirement for building custom tag entries by prefixing certain attributes present in jwt token (Kind of key templating) . We were unable to solve this without custom decorator at the time we started this. Please let me know , if these can be solved without custom decorator.
PS : I just saw documentation about CacheDeleteMiddleware. It was not there earlier when we started with this.
re.escape
a) yes you can bypass and remove cache by wrap call to context manager invalidate_further
- for example add a middleware to your fastapi app
from cashews import invalidate_further
async def middleware(request, call_next): if request.headers.get(_YOUR_HEARED) == _CLEAR_CACHE_HEADER_VALUE: with invalidate_further(): return await call_next(request)
return await call_next(request)
b) yes probably now we can't use advance templating in tags ( like in keys) - it is easy to fix and this [MR](https://github.com/Krukov/cashews/pull/188) implement it - and it will looks like following
```python
@cache(ttl="1h", tags=["items", "client_id:{token:jwt(client_id)}"])
Fixed in 7.0.0
Hi @Krukov , I am using a custom decorator on top of @cache decorator to enhance it to achieve some of our custom requirements. My custom decorator code is given below.
I am getting TagNotRegisteredError , when by key have some special characters like '$' , '?' etc. Providing the error log and our custom decorator code below.
Used redis and cashews modules : redis-py=5.0.0 cashews=6.3.0
Error :
Custom decorator implementation