GithubHelp home page GithubHelp logo

Comments (5)

Krukov avatar Krukov commented on August 25, 2024 1

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.

Krukov avatar Krukov commented on August 25, 2024

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.

rueschm avatar rueschm commented on August 25, 2024

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.

Krukov avatar Krukov commented on August 25, 2024

not released yet

from cashews.

Krukov avatar Krukov commented on August 25, 2024

Fixed with 7.1.0 version. Feel free to reopen the issue if it still exist

from cashews.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.