EasyCaching Cache is shared & persistent a Key / Value store, backed by a familiar RBDMS.

Basic Usage

Create EasyCacheManager

import asyncio
from easycaching import EasyCacheManager

async def main():
    # create EasyCache instance
    cache = await EasyCacheManager.create(

Create Cache instance

    # inside main()
    test = await cache.create_cache('test')

Adding Data to Cache

    # set
    await test.set('foo', 'bar')

Getting Data from Cache

    cached_value = await test.get('foo')

Checking if Key Exists

    # boolean
    exists = await test.contains('foo')

Delete data from Cache

Removing a single Key

    # delete
    await test.delete('foo')

Removing all entries from a cache

    await test.clear()

Iterating over data in Cache

    async for cache_item in test:
{'foo': 'bar'}
{'is': 'basic'}

Accessing Cache via Manager

If a cache already exists, it is also accessible via manager

    await cache.cache['test'].set('first', 'worst')
    await cache.cache['test'].set('second', 'best')
    await cache.cache['test'].set('third', 'treasure chest')

Safely Exiting EasyCacheManager

To ensure Easycaching correctly exits, ensure that .close() is awaited each time.

    await cache.close()

FastAPI Usage

EasyCaching integrates very easily into the FastAPI ecosystem

from fastapi import FastAPI
from easycaching import EasyCacheManager

app = FastAPI()

async def start_cache():
    app.cache = await EasyCacheManager.create(
    # create cache instance
    await app.cache.create_cache('test')

async def view_cache(key: str):
    return {
        key:  await app.cache.cache['test'][key]
async def set_cache(key: str, value: str):
    return await app.cache.cache['test'].set(
        {'json': value}

uvicorn --host --port 8220 --workers 5 basic:app