EasyCaching Queue is shared & persistent a Queue, 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 Queue

    # create queue
    test_queue = await cache.create_queue('test')

Adding Data to a Queue

    # add items to queue
    await test_queue.put('first')
    await test_queue.put('second')
    await test_queue.put('third')

Consuming Data from a Queue

Data in queues persist until consumed via .get()

    # grab items from queue
    result = await test_queue.get()
    await test_queue.get() # second
    await test_queue.get() # third
    result = await test_queue.get() # empty
{'warning': 'queue empty'}

Clearing a Queue

Data is removed when consumed or via .clear()

    await test_queue.clear()

Accessing Queue via Manager

Like Cache, Queue is accessible, if already created, via Manager:

    await cache.queues['test'].put('fourth')
    await cache.queues['test'].put('fifth')    

Safely Exiting EasyCacheManager

    await cache.close()

FastAPI Usage

from fastapi import FastAPI
from easycaching import EasyCache

app = FastAPI()

async def start_cache():
    app.cache = await EasyCacheManager.create(
    await app.cache.create_queue('test')

async def create_queue(name: str):
    queue = await app.cache.create_queue(name)
    return f"queue {name} created"

async def add_to_queue(queue: str, data: dict):
    return await cache.queues[queue].put(data)

async def pull_from_queue(queue: str):
    return await cache.queues[queue].get()
uvicorn --host --port 8220 --workers 5 basic:app