Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs: Update stale caching example #3442

Open
JacobCoffee opened this issue Apr 27, 2024 · 0 comments · May be fixed by #3514
Open

Docs: Update stale caching example #3442

JacobCoffee opened this issue Apr 27, 2024 · 0 comments · May be fixed by #3514

Comments

@JacobCoffee
Copy link
Member

JacobCoffee commented Apr 27, 2024

I think this is a remnant of an old pattern. IIUC the snippet in the docs would no longer work.

The following is an MCVE that shows how to use a custom store using the current interfaces.

import asyncio
from litestar import Litestar, get
from litestar.config.response_cache import ResponseCacheConfig
from litestar.stores.redis import RedisStore


@get(cache=10)
async def something() -> str:
    await asyncio.sleep(1)
    return "something"


redis_store = RedisStore.with_client(url="redis://localhost", port=6379, db=0)
cache_config = ResponseCacheConfig(store="redis_backed_store")
app = Litestar(
    [something],
    stores={"redis_backed_store": redis_store},
    response_cache_config=cache_config,
)

Some may argue this is not good DX, I personally do not find this any difficult.

IOW, the following are lines of interest. The store has to be configured at the app level and the same name has to be used in ResponseCacheConfig.store. The existing snippet passes a Store instance itself, which I do not think the current interface accepts.

redis_store = RedisStore.with_client(url="redis://localhost", port=6379, db=0)
cache_config = ResponseCacheConfig(store="redis_backed_store")
app = Litestar(
    [something],
    stores={"redis_backed_store": redis_store},
    response_cache_config=cache_config,
)

Originally posted by @Alc-Alc in #3345 (comment)


Note

While we are open for sponsoring on GitHub Sponsors and
OpenCollective, we also utilize Polar.sh to engage in pledge-based sponsorship.

Check out all issues funded or available for funding on our Polar.sh dashboard

  • If you would like to see an issue prioritized, make a pledge towards it!
  • We receive the pledge once the issue is completed & verified
  • This, along with engagement in the community, helps us know which features are a priority to our users.
Fund with Polar
@tibor-reiss tibor-reiss linked a pull request May 19, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant