Skip to content
This repository has been archived by the owner on Feb 23, 2020. It is now read-only.

Implement never_cache decorator #5

Open
florimondmanca opened this issue Nov 3, 2019 · 0 comments
Open

Implement never_cache decorator #5

florimondmanca opened this issue Nov 3, 2019 · 0 comments
Labels
good first issue Good for newcomers

Comments

@florimondmanca
Copy link
Owner

florimondmanca commented Nov 3, 2019

Currently, when CacheMiddleware is applied then all application endpoints will be cached according to the cache.ttl. Users may want to not cache a specific endpoint, e.g. because its response should always be fresh.

The proposed API is a new @never_cache decorator:

from datetime import datetime
from asgi_caches.decorators import never_cache

@app.route("/datetime")
@never_cache
class DateTime(HTTPEndpoint):
    async def get(self, request):
        return JSONResponse({"time": datetime.now().utcformat()})

Alternatives that were considered:

  • Use @cached(ttl=0): this would work, as currently if the TTL is zero we do not cache at all (see Don't cache if TTL is 0 #10), but it is not the most intuitive API.

To implement this feature:

  • Add the @never_cache decorator in decorators.py. You may want to implement it as a proxy to @cached(ttl=0), if it turns out to work.
  • Add a test that if the decorator is applied, the endpoint is not cached even if the application is wrapped in CacheMiddleware.

(Note: the situation where both @cached and @never_cache isn't within the scope of this issue. It will be dealt with as part of #16.)

@florimondmanca florimondmanca changed the title Implement no cache decorator Implement never_cache decorator Nov 3, 2019
@florimondmanca florimondmanca added the good first issue Good for newcomers label Nov 12, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant