Comments (5)
Oh got you, catch it, that is because of logic with etag (You requests have a Etag header and we just check that we have this etag in a cache). I will try to fix it somehow asap
from cashews.
Hi , thanks for notifying but I couldn't reproduce this issue. It will be grateful if you will provide a piece of code to reproduce it
from cashews.
Hi, thanks for your response, here a minimal code sample:
import datetime
from cashews import cache
from cashews.contrib.fastapi import CacheEtagMiddleware
from fastapi import FastAPI
app = FastAPI()
@app.on_event("startup")
async def startup_event():
cache.setup("mem://")
app.add_middleware(CacheEtagMiddleware)
@app.get("/test")
@cache.early(ttl="5m", early_ttl="1m")
async def test():
print(datetime.datetime.now()," refresh")
return {"hello": "world"}
I start the application and then make a request every minute to http://localhost:8000/test. The logs are:
INFO: Started server process [77581]
INFO: Waiting for application startup.
INFO: Application startup complete.
2024-02-14 15:00:27.698238 refresh
INFO: 127.0.0.1:50270 - "GET /test HTTP/1.1" 200 OK
INFO: 127.0.0.1:50289 - "GET /test HTTP/1.1" 304 Not Modified
INFO: 127.0.0.1:50291 - "GET /test HTTP/1.1" 304 Not Modified
INFO: 127.0.0.1:50298 - "GET /test HTTP/1.1" 304 Not Modified
INFO: 127.0.0.1:50300 - "GET /test HTTP/1.1" 304 Not Modified
2024-02-14 15:05:38.306540 refresh
INFO: 127.0.0.1:50315 - "GET /test HTTP/1.1" 200 OK
As you can see in the logs the first time the function is executed again not taken from the cache is after 5 minutes.
In my understanding this should happen after 1 minute already. I am also not completely sure why the response code after the 5 minute and the refresh i then 200. As the result is still the same it could be 304 as well.
If I remove the line
app.add_middleware(CacheEtagMiddleware)
the logs are:
INFO: Started server process [77980]
INFO: Waiting for application startup.
INFO: Application startup complete.
2024-02-14 15:07:01.202219 refresh
INFO: 127.0.0.1:50327 - "GET /test HTTP/1.1" 200 OK
INFO: 127.0.0.1:50329 - "GET /test HTTP/1.1" 200 OK
2024-02-14 15:08:30.271739 refresh
INFO: 127.0.0.1:50339 - "GET /test HTTP/1.1" 200 OK
now the first refresh happens already after 1 minute. That is the behaviour I would expect.
Pip freeze:
annotated-types==0.6.0
anyio==4.2.0
cashews==7.0.0
click==8.1.7
fastapi==0.109.2
h11==0.14.0
idna==3.6
pydantic==2.6.1
pydantic_core==2.16.2
sniffio==1.3.0
starlette==0.36.3
typing_extensions==4.9.0
uvicorn==0.27.1
from cashews.
not released yet
from cashews.
Fixed with 7.1.0 version. Feel free to reopen the issue if it still exist
from cashews.
Related Issues (20)
- Gracefully close a connection pool with redis > 5.0.1
- Cannot close Redis connection - AttributeError: 'Redis' object has no attribute '_client' HOT 4
- Cache doesn't work with GZIPMiddleware HOT 5
- JSON serializer HOT 5
- Early cache with sqlalchemy & fastapi depend (sqlalchemy.exc.IllegalStateChangeError: Method 'close()' can't be called here; method '_connection_for_bind()' is already in progress and this would cause an unexpected state change to <SessionTransactionState.CLOSED: 5>) HOT 1
- Formatter Called with Formatted Value HOT 9
- CacheRequestControlMiddleware: Backend not found exception with non-default cache prefix HOT 3
- cache_control_ttl can't be used directly with cache api HOT 1
- thunder_protection with multiple event loops breaks HOT 3
- re.error: bad character in group name when using custom formatter in a tag HOT 3
- Unhandled exception when there are only backends with prefixes HOT 2
- Feature: Get or set HOT 1
- _empty and _empty_in_redis marker objects leak HOT 1
- Redis Client Side Connection Timeout HOT 6
- Interrupted `StreamingResponse` will cache partial response HOT 3
- The `add_prefix` middleware didn't consider `delete_many` HOT 1
- Problem with codecov
- valkeys backend HOT 1
- Early caching unexpected behavior: Altered keys breaking other api calls HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cashews.