Skip to content

Commit 3a0b499

Browse files
committed
refactor(backend): remove BaseBackend
1 parent 5186d52 commit 3a0b499

File tree

4 files changed

+12
-15
lines changed

4 files changed

+12
-15
lines changed

class_cache/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Caching for class based generators"""
22

3-
from .backends import BaseBackend
43
from .core import Cache, CacheWithDefault
4+
from .types import CacheInterface
55
from .wrappers import BaseWrapper
66

77
__version__ = "0.7.0"

class_cache/backends.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,7 @@
1818
LOGGER = logging.getLogger(__name__)
1919

2020

21-
class BaseBackend(CacheInterface[KeyType, ValueType]):
22-
pass
23-
24-
25-
class PickleBackend(BaseBackend[KeyType, ValueType]):
21+
class PickleBackend(CacheInterface[KeyType, ValueType]):
2622
ROOT_DIR = get_class_cache_dir() / "PickleBackend"
2723
BLOCK_SUFFIX = ".block.pkl"
2824
META_TYPE = dict[str, Any]
@@ -163,7 +159,7 @@ def clear(self) -> None:
163159
self._write_clean_meta()
164160

165161

166-
class SQLiteBackend(BaseBackend[KeyType, ValueType]):
162+
class SQLiteBackend(CacheInterface[KeyType, ValueType]):
167163
ROOT_DIR = get_class_cache_dir() / "SQLiteBackend"
168164
ROOT_DIR.mkdir(parents=True, exist_ok=True)
169165
DATA_TABLE_NAME = "data"

class_cache/core.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33

44
from replete.consistent_hash import consistent_hash
55

6-
from class_cache.backends import BaseBackend, PickleBackend
6+
from class_cache.backends import PickleBackend
77
from class_cache.types import CacheInterface, KeyType, ValueType
88

99
DEFAULT_BACKEND_TYPE = PickleBackend
1010

1111

1212
class Cache(CacheInterface[KeyType, ValueType]):
13-
def __init__(self, id_: str | int | None = None, backend_type: type[BaseBackend] = DEFAULT_BACKEND_TYPE) -> None:
13+
def __init__(self, id_: str | int | None = None, backend_type: type[CacheInterface] = DEFAULT_BACKEND_TYPE) -> None:
1414
super().__init__(id_)
1515
self._backend = backend_type(id_)
1616
# TODO: Implement max_size logic
@@ -19,7 +19,7 @@ def __init__(self, id_: str | int | None = None, backend_type: type[BaseBackend]
1919
self._to_delete = set()
2020

2121
@property
22-
def backend(self) -> BaseBackend:
22+
def backend(self) -> CacheInterface:
2323
return self._backend
2424

2525
def __contains__(self, key: KeyType) -> bool:
@@ -71,7 +71,7 @@ class CacheWithDefault(Cache[KeyType, ValueType]):
7171
{"_backend", "_backend_set", "_data", "_to_write", "_to_delete"},
7272
)
7373

74-
def __init__(self, backend: type[BaseBackend] = DEFAULT_BACKEND_TYPE):
74+
def __init__(self, backend: type[CacheInterface] = DEFAULT_BACKEND_TYPE):
7575
super().__init__(self.id_for_backend, backend)
7676
self._backend_set = True
7777

tests/test_backends.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33

44
import pytest
55

6-
from class_cache.backends import BaseBackend, PickleBackend, SQLiteBackend
6+
from class_cache.backends import PickleBackend, SQLiteBackend
7+
from class_cache.types import CacheInterface
78

89
MAX_WORKERS = 16
910
INCREASE_AMOUNT = 32
1011

1112

12-
def _increase_cache(backend_type: type[BaseBackend], offset: int):
13+
def _increase_cache(backend_type: type[CacheInterface], offset: int):
1314
backend = backend_type()
1415
for idx in range(INCREASE_AMOUNT):
1516
num = offset + idx
@@ -18,7 +19,7 @@ def _increase_cache(backend_type: type[BaseBackend], offset: int):
1819

1920
@pytest.mark.parametrize(("backend_type"), [PickleBackend, SQLiteBackend])
2021
class TestCore:
21-
def test_basic(self, test_id, test_key, test_value, backend_type: type[BaseBackend]):
22+
def test_basic(self, test_id, test_key, test_value, backend_type: type[CacheInterface]):
2223
backend = backend_type(test_id)
2324
backend.clear()
2425
assert test_key not in backend
@@ -30,7 +31,7 @@ def test_basic(self, test_id, test_key, test_value, backend_type: type[BaseBacke
3031
del backend[test_key]
3132
assert test_key not in backend
3233

33-
def test_write_read(self, test_id, test_key, test_value, backend_type: type[BaseBackend]):
34+
def test_write_read(self, test_id, test_key, test_value, backend_type: type[CacheInterface]):
3435
write_backend = backend_type(test_id)
3536
write_backend.clear()
3637
assert test_key not in write_backend

0 commit comments

Comments
 (0)