from __future__ import annotations

import threading
from pathlib import Path

from mockmesh.storage.nosql import NoSQLStorage
from mockmesh.storage.utils import route_subdir

_CACHE_ROUTES: list = [
    ("clusters", "aws"),
    ("replication_groups", "aws"),
    ("redis_", "redis"),
]


class CacheStorage(NoSQLStorage):

    backend_type = "cache"

    def __init__(self, root: Path) -> None:
        from mockmesh.storage.base import BaseStorage
        BaseStorage.__init__(self, root)
        self._store_dir = root / "cache"
        self._locks: dict = {}
        self._global_lock = threading.Lock()

    @staticmethod
    def _route_subdir(collection: str) -> str:
        return route_subdir(collection, _CACHE_ROUTES)
