|
1 |
| -from os import PathLike |
2 |
| -from typing import ContextManager |
3 |
| - |
4 |
| -from ..cache import BaseCache as BaseCache |
5 |
| -from ..controller import CacheController as CacheController |
| 1 | +from cachecontrol.cache import SeparateBodyBaseCache |
| 2 | +from datetime import datetime |
| 3 | +from filelock import BaseFileLock |
| 4 | +from pathlib import Path |
| 5 | +from typing import IO, ContextManager |
6 | 6 |
|
7 | 7 | class _LockClass:
|
8 | 8 | path: str
|
9 | 9 |
|
10 | 10 | _lock_class = ContextManager[_LockClass]
|
11 | 11 |
|
12 |
| -class FileCache(BaseCache): |
| 12 | +class _FileCacheMixin: |
13 | 13 | directory: str
|
14 | 14 | forever: bool
|
15 | 15 | filemode: int
|
16 | 16 | dirmode: int
|
17 | 17 | lock_class: _lock_class | None = None
|
18 | 18 | def __init__(
|
19 | 19 | self,
|
20 |
| - directory: str | PathLike[str], |
21 |
| - forever: bool = ..., |
22 |
| - filemode: int = ..., |
23 |
| - dirmode: int = ..., |
24 |
| - use_dir_lock: bool | None = ..., |
25 |
| - lock_class: _lock_class | None = ..., |
| 20 | + directory: str | Path, |
| 21 | + forever: bool = False, |
| 22 | + filemode: int = 384, |
| 23 | + dirmode: int = 448, |
| 24 | + lock_class: type[BaseFileLock] | None = None, |
26 | 25 | ) -> None: ...
|
27 | 26 | @staticmethod
|
28 | 27 | def encode(x: str) -> str: ...
|
29 |
| - def get(self, key: str) -> None | bytes: ... |
30 |
| - def set(self, key: str, value: bytes, expires: int | None = None) -> None: ... |
| 28 | + def get(self, key: str) -> bytes | None: ... |
| 29 | + def set(self, key: str, value: bytes, expires: int | datetime | None = None) -> None: ... |
| 30 | + |
| 31 | +class SeparateBodyFileCache(_FileCacheMixin, SeparateBodyBaseCache): |
| 32 | + def get_body(self, key: str) -> IO[bytes] | None: ... |
| 33 | + def set_body(self, key: str, body: bytes) -> None: ... |
31 | 34 | def delete(self, key: str) -> None: ...
|
0 commit comments