# Path: virtool/types.py



from typing import Any, Dict
from virtool.types import App
import pymongo.errors
import virtool.utils

    """
    try:
        cache_id = virtool.utils.random_alphanumeric(length=8)

        document = {
            "_id": cache_id,
            "created_at": virtool.utils.timestamp(),
            "files": list(),
            "key": key,
            "legacy": False,
            "missing": False,
            "paired": paired,
            "ready": False,
            "sample": {"id": sample_id},
        }

        await db.caches.insert_one(document)

        return virtool.utils.base_processor(document)

    except pymongo.errors.DuplicateKeyError as e:
        # Check if key-sample.id uniqueness was enforced
        # Keep trying to add the cache with new ids if the generated id is not unique.
        if "_id" in e.details["keyPattern"]:
            return await create(db, sample_id, key, paired)

        raise



# Path: virtool/types.py



# Path: virtool/caches/db.py
from typing import Any, Dict
from virtool.types import App
import pymongo.errors
import virtool.utils


    """
    try:
        cache_id = virtool.utils.random_alphanumeric(length=8)

        document = {
            "_id": cache_id,
            "created_at": virtool.utils.timestamp(),
            "files": list(),
            "key": key,
            "legacy": False,
            "missing": False,
            "paired": paired,
            "ready": False,
            "sample": {"id": sample_id},
        }

        await db.caches.insert_one(document)

        return virtool.utils.base_processor(document)

    except pymongo.errors.DuplicateKeyError as e:
        # Check if key-sample.id uniqueness was enforced
        # Keep trying to add the cache with new ids if the generated id is not unique.
        if "_id" in e.details["keyPattern"]:
            return await create(db, sample_id, key, paired)

        raise



async def remove(app: App, cache_id: str):