示例#1
0
async def on_startup() -> None:
    # Necessary for testing, because dependency injection
    # works in path operations only, eg. functions.
    settings = app.dependency_overrides.get(get_settings, get_settings)()

    rc = RedisCacheBackend(settings.redis_dsn)
    # Testing can possibly trigger lifespan events multiple times,
    # and cache registry raise an error if an entry is already registered.
    if caches.get(CACHE_KEY):
        caches.remove(CACHE_KEY)
    caches.set(CACHE_KEY, rc)
示例#2
0
def redis_cache():
    return caches.get(CACHE_KEY)
示例#3
0
def cache():
    return caches.get(CACHE_KEY)
示例#4
0
def redis_cache() -> Optional[BaseCacheBackend]:
    return caches.get(CACHE_KEY)