Skip to content

Direct backend class or a decorator usage without calling setup #106

Answered by Krukov
simon-liebehenschel asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @AIGeneratedUsername .

  1. It is possible now. User don't need to call setup if he want to use backends directly
import asyncio
import random

from cashews.backends.redis import Redis
from cashews.decorators.cache.simple import cache


async def func():
    backend = Redis("redis://localhost")
    await backend.init()

    @cache(backend=backend, ttl="10m", prefix="hash")
    async def get_token():
        ...

    print(await get_token())


asyncio.run(func())

setup is a part of the cache wrapper that handle: multibackend, middleware, autoinit, disable/enable functionality.

By the way now user can use his own backend fully integrated in cashews by register_backend function

from cashews.b…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by simon-liebehenschel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants