diskcache-rs 0.4.0__cp314-cp314-win32.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- diskcache_rs/__init__.py +47 -0
- diskcache_rs/__init__.pyi +215 -0
- diskcache_rs/_diskcache_rs.cp314-win32.pyd +0 -0
- diskcache_rs/_diskcache_rs.pyi +150 -0
- diskcache_rs/cache.py +576 -0
- diskcache_rs/core.py +41 -0
- diskcache_rs/fast_cache.py +373 -0
- diskcache_rs/pickle_cache.py +257 -0
- diskcache_rs/rust_pickle.py +71 -0
- diskcache_rs-0.4.0.dist-info/METADATA +684 -0
- diskcache_rs-0.4.0.dist-info/RECORD +13 -0
- diskcache_rs-0.4.0.dist-info/WHEEL +4 -0
- diskcache_rs-0.4.0.dist-info/licenses/LICENSE +195 -0
diskcache_rs/__init__.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"""
|
|
2
|
+
DiskCache RS - A high-performance disk cache implementation in Rust with Python bindings
|
|
3
|
+
|
|
4
|
+
This module provides a Python interface compatible with python-diskcache,
|
|
5
|
+
but implemented in Rust for better performance and network filesystem support.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
# Always use the Python wrapper for now
|
|
9
|
+
# The Python wrapper will handle importing the Rust implementation
|
|
10
|
+
from .cache import Cache, FanoutCache
|
|
11
|
+
from .fast_cache import FastCache, FastFanoutCache
|
|
12
|
+
from .pickle_cache import PickleCache, cache_object, clear_cache, get_cached_object
|
|
13
|
+
|
|
14
|
+
# Import Rust pickle functions
|
|
15
|
+
try:
|
|
16
|
+
from ._diskcache_rs import rust_pickle_dumps, rust_pickle_loads
|
|
17
|
+
except ImportError:
|
|
18
|
+
rust_pickle_dumps = None
|
|
19
|
+
rust_pickle_loads = None
|
|
20
|
+
|
|
21
|
+
# Version is managed by maturin and synced from Cargo.toml
|
|
22
|
+
try:
|
|
23
|
+
from importlib.metadata import version, PackageNotFoundError
|
|
24
|
+
except ImportError:
|
|
25
|
+
# Python 3.7 fallback
|
|
26
|
+
from importlib_metadata import version, PackageNotFoundError # type: ignore
|
|
27
|
+
|
|
28
|
+
try:
|
|
29
|
+
__version__ = version("diskcache_rs")
|
|
30
|
+
except PackageNotFoundError:
|
|
31
|
+
# Development mode fallback
|
|
32
|
+
__version__ = "0.0.0-dev"
|
|
33
|
+
__all__ = [
|
|
34
|
+
"Cache",
|
|
35
|
+
"FanoutCache",
|
|
36
|
+
"PickleCache",
|
|
37
|
+
"cache_object",
|
|
38
|
+
"get_cached_object",
|
|
39
|
+
"clear_cache",
|
|
40
|
+
"FastCache",
|
|
41
|
+
"FastFanoutCache",
|
|
42
|
+
"rust_pickle_dumps",
|
|
43
|
+
"rust_pickle_loads",
|
|
44
|
+
]
|
|
45
|
+
|
|
46
|
+
# For backward compatibility
|
|
47
|
+
DiskCache = Cache
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Type stubs for diskcache_rs package
|
|
3
|
+
|
|
4
|
+
This package provides a high-performance disk cache implementation in Rust
|
|
5
|
+
with Python bindings, compatible with python-diskcache API.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
from typing import Any, Dict, Iterator, List, Optional, Union
|
|
10
|
+
|
|
11
|
+
# Version
|
|
12
|
+
__version__: str
|
|
13
|
+
|
|
14
|
+
# Main Cache Classes
|
|
15
|
+
class Cache:
|
|
16
|
+
"""High-performance disk cache compatible with python-diskcache API"""
|
|
17
|
+
|
|
18
|
+
def __init__(
|
|
19
|
+
self,
|
|
20
|
+
directory: Optional[Union[str, Path]] = None,
|
|
21
|
+
timeout: float = 60.0,
|
|
22
|
+
disk_min_file_size: int = 32768,
|
|
23
|
+
**kwargs: Any,
|
|
24
|
+
) -> None: ...
|
|
25
|
+
def __contains__(self, key: Any) -> bool: ...
|
|
26
|
+
def __enter__(self) -> Cache: ...
|
|
27
|
+
def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None: ...
|
|
28
|
+
def __getitem__(self, key: Any) -> Any: ...
|
|
29
|
+
def __setitem__(self, key: Any, value: Any) -> None: ...
|
|
30
|
+
def __delitem__(self, key: Any) -> None: ...
|
|
31
|
+
def __iter__(self) -> Iterator[Any]: ...
|
|
32
|
+
def __len__(self) -> int: ...
|
|
33
|
+
def get(self, key: Any, default: Any = None, retry: bool = False) -> Any: ...
|
|
34
|
+
def set(
|
|
35
|
+
self, key: Any, value: Any, expire: Optional[float] = None, retry: bool = False
|
|
36
|
+
) -> bool: ...
|
|
37
|
+
def add(
|
|
38
|
+
self, key: Any, value: Any, expire: Optional[float] = None, retry: bool = False
|
|
39
|
+
) -> bool: ...
|
|
40
|
+
def delete(self, key: Any, retry: bool = False) -> bool: ...
|
|
41
|
+
def pop(
|
|
42
|
+
self,
|
|
43
|
+
key: Any,
|
|
44
|
+
default: Any = None,
|
|
45
|
+
expire: Optional[float] = None,
|
|
46
|
+
retry: bool = False,
|
|
47
|
+
) -> Any: ...
|
|
48
|
+
def clear(self, retry: bool = False) -> int: ...
|
|
49
|
+
def close(self) -> None: ...
|
|
50
|
+
def exists(self, key: Any) -> bool: ...
|
|
51
|
+
def keys(self) -> Iterator[Any]: ...
|
|
52
|
+
def values(self) -> Iterator[Any]: ...
|
|
53
|
+
def items(self) -> Iterator[tuple[Any, Any]]: ...
|
|
54
|
+
def iterkeys(self) -> Iterator[Any]: ...
|
|
55
|
+
def itervalues(self) -> Iterator[Any]: ...
|
|
56
|
+
def iteritems(self) -> Iterator[tuple[Any, Any]]: ...
|
|
57
|
+
def expire(self, now: Optional[float] = None) -> int: ...
|
|
58
|
+
def evict(self, tag: Optional[str] = None) -> int: ...
|
|
59
|
+
def stats(self, enable: bool = True, reset: bool = False) -> tuple[int, int]: ...
|
|
60
|
+
def volume(self) -> int: ...
|
|
61
|
+
def reset(self, key: str, value: Any = None) -> None: ...
|
|
62
|
+
def touch(
|
|
63
|
+
self, key: Any, expire: Optional[float] = None, retry: bool = False
|
|
64
|
+
) -> bool: ...
|
|
65
|
+
def incr(
|
|
66
|
+
self,
|
|
67
|
+
key: Any,
|
|
68
|
+
delta: Union[int, float] = 1,
|
|
69
|
+
default: Union[int, float] = 0,
|
|
70
|
+
retry: bool = False,
|
|
71
|
+
) -> Union[int, float]: ...
|
|
72
|
+
def decr(
|
|
73
|
+
self,
|
|
74
|
+
key: Any,
|
|
75
|
+
delta: Union[int, float] = 1,
|
|
76
|
+
default: Union[int, float] = 0,
|
|
77
|
+
retry: bool = False,
|
|
78
|
+
) -> Union[int, float]: ...
|
|
79
|
+
|
|
80
|
+
# Properties
|
|
81
|
+
@property
|
|
82
|
+
def directory(self) -> Path: ...
|
|
83
|
+
|
|
84
|
+
class FanoutCache:
|
|
85
|
+
"""Fanout cache implementation for better concurrency"""
|
|
86
|
+
|
|
87
|
+
def __init__(
|
|
88
|
+
self,
|
|
89
|
+
directory: Optional[Union[str, Path]] = None,
|
|
90
|
+
shards: int = 8,
|
|
91
|
+
timeout: float = 60.0,
|
|
92
|
+
**kwargs: Any,
|
|
93
|
+
) -> None: ...
|
|
94
|
+
def __contains__(self, key: Any) -> bool: ...
|
|
95
|
+
def __enter__(self) -> FanoutCache: ...
|
|
96
|
+
def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None: ...
|
|
97
|
+
def __getitem__(self, key: Any) -> Any: ...
|
|
98
|
+
def __setitem__(self, key: Any, value: Any) -> None: ...
|
|
99
|
+
def __delitem__(self, key: Any) -> None: ...
|
|
100
|
+
def __iter__(self) -> Iterator[Any]: ...
|
|
101
|
+
def __len__(self) -> int: ...
|
|
102
|
+
def get(self, key: Any, default: Any = None, retry: bool = False) -> Any: ...
|
|
103
|
+
def set(
|
|
104
|
+
self, key: Any, value: Any, expire: Optional[float] = None, retry: bool = False
|
|
105
|
+
) -> bool: ...
|
|
106
|
+
def add(
|
|
107
|
+
self, key: Any, value: Any, expire: Optional[float] = None, retry: bool = False
|
|
108
|
+
) -> bool: ...
|
|
109
|
+
def delete(self, key: Any, retry: bool = False) -> bool: ...
|
|
110
|
+
def pop(
|
|
111
|
+
self,
|
|
112
|
+
key: Any,
|
|
113
|
+
default: Any = None,
|
|
114
|
+
expire: Optional[float] = None,
|
|
115
|
+
retry: bool = False,
|
|
116
|
+
) -> Any: ...
|
|
117
|
+
def clear(self, retry: bool = False) -> int: ...
|
|
118
|
+
def close(self) -> None: ...
|
|
119
|
+
def exists(self, key: Any) -> bool: ...
|
|
120
|
+
def keys(self) -> Iterator[Any]: ...
|
|
121
|
+
def values(self) -> Iterator[Any]: ...
|
|
122
|
+
def items(self) -> Iterator[tuple[Any, Any]]: ...
|
|
123
|
+
def expire(self, now: Optional[float] = None) -> int: ...
|
|
124
|
+
def evict(self, tag: Optional[str] = None) -> int: ...
|
|
125
|
+
def stats(self, enable: bool = True, reset: bool = False) -> tuple[int, int]: ...
|
|
126
|
+
def volume(self) -> int: ...
|
|
127
|
+
def reset(self, key: str, value: Any = None) -> None: ...
|
|
128
|
+
def touch(
|
|
129
|
+
self, key: Any, expire: Optional[float] = None, retry: bool = False
|
|
130
|
+
) -> bool: ...
|
|
131
|
+
def incr(
|
|
132
|
+
self,
|
|
133
|
+
key: Any,
|
|
134
|
+
delta: Union[int, float] = 1,
|
|
135
|
+
default: Union[int, float] = 0,
|
|
136
|
+
retry: bool = False,
|
|
137
|
+
) -> Union[int, float]: ...
|
|
138
|
+
def decr(
|
|
139
|
+
self,
|
|
140
|
+
key: Any,
|
|
141
|
+
delta: Union[int, float] = 1,
|
|
142
|
+
default: Union[int, float] = 0,
|
|
143
|
+
retry: bool = False,
|
|
144
|
+
) -> Union[int, float]: ...
|
|
145
|
+
|
|
146
|
+
# Fast Cache Classes
|
|
147
|
+
class FastCache(Cache):
|
|
148
|
+
"""Ultra-fast cache implementation with optimized storage backends"""
|
|
149
|
+
|
|
150
|
+
pass
|
|
151
|
+
|
|
152
|
+
class FastFanoutCache(FanoutCache):
|
|
153
|
+
"""Ultra-fast fanout cache implementation"""
|
|
154
|
+
|
|
155
|
+
pass
|
|
156
|
+
|
|
157
|
+
# Pickle Cache
|
|
158
|
+
class PickleCache:
|
|
159
|
+
"""High-performance pickle cache with expiration support"""
|
|
160
|
+
|
|
161
|
+
def __init__(self, cache_dir: Union[str, Path] = "pickle_cache") -> None: ...
|
|
162
|
+
def cache_object(self, key: str, obj: Any, expire_hours: float = 24.0) -> None: ...
|
|
163
|
+
def get_cached_object(self, key: str) -> Optional[Any]: ...
|
|
164
|
+
def clear_cache(self) -> None: ...
|
|
165
|
+
def is_expired(self, key: str) -> bool: ...
|
|
166
|
+
def delete_object(self, key: str) -> bool: ...
|
|
167
|
+
def list_cached_objects(self) -> List[str]: ...
|
|
168
|
+
def get_cache_stats(self) -> Dict[str, Any]: ...
|
|
169
|
+
|
|
170
|
+
# Utility Functions
|
|
171
|
+
def cache_object(
|
|
172
|
+
key: str,
|
|
173
|
+
obj: Any,
|
|
174
|
+
expire_hours: float = 24.0,
|
|
175
|
+
cache_dir: Union[str, Path] = "pickle_cache",
|
|
176
|
+
) -> None:
|
|
177
|
+
"""Cache an object with expiration"""
|
|
178
|
+
...
|
|
179
|
+
|
|
180
|
+
def get_cached_object(
|
|
181
|
+
key: str, cache_dir: Union[str, Path] = "pickle_cache"
|
|
182
|
+
) -> Optional[Any]:
|
|
183
|
+
"""Retrieve a cached object"""
|
|
184
|
+
...
|
|
185
|
+
|
|
186
|
+
def clear_cache(cache_dir: Union[str, Path] = "pickle_cache") -> None:
|
|
187
|
+
"""Clear all cached objects"""
|
|
188
|
+
...
|
|
189
|
+
|
|
190
|
+
# Rust Functions (from _diskcache_rs module)
|
|
191
|
+
def rust_pickle_dumps(obj: Any) -> Any:
|
|
192
|
+
"""High-performance pickle serialization using Rust"""
|
|
193
|
+
...
|
|
194
|
+
|
|
195
|
+
def rust_pickle_loads(data: Any) -> Any:
|
|
196
|
+
"""High-performance pickle deserialization using Rust"""
|
|
197
|
+
...
|
|
198
|
+
|
|
199
|
+
# Backward compatibility
|
|
200
|
+
DiskCache = Cache
|
|
201
|
+
|
|
202
|
+
# All exports
|
|
203
|
+
__all__ = [
|
|
204
|
+
"Cache",
|
|
205
|
+
"FanoutCache",
|
|
206
|
+
"FastCache",
|
|
207
|
+
"FastFanoutCache",
|
|
208
|
+
"PickleCache",
|
|
209
|
+
"cache_object",
|
|
210
|
+
"get_cached_object",
|
|
211
|
+
"clear_cache",
|
|
212
|
+
"rust_pickle_dumps",
|
|
213
|
+
"rust_pickle_loads",
|
|
214
|
+
"DiskCache",
|
|
215
|
+
]
|
|
Binary file
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
# Type stubs for _diskcache_rs module (Rust extension)
|
|
2
|
+
# This file is automatically generated by pyo3_stub_gen
|
|
3
|
+
# ruff: noqa: E501, F401
|
|
4
|
+
|
|
5
|
+
import builtins
|
|
6
|
+
import typing
|
|
7
|
+
from typing import Any, Dict, List, Optional
|
|
8
|
+
|
|
9
|
+
# Rust Cache Classes
|
|
10
|
+
class PyCache:
|
|
11
|
+
"""Python wrapper for the Cache"""
|
|
12
|
+
def __init__(
|
|
13
|
+
self,
|
|
14
|
+
directory: str,
|
|
15
|
+
max_size: Optional[int] = None,
|
|
16
|
+
max_entries: Optional[int] = None,
|
|
17
|
+
) -> None: ...
|
|
18
|
+
def get(self, key: str) -> Optional[bytes]: ...
|
|
19
|
+
def set(
|
|
20
|
+
self,
|
|
21
|
+
key: str,
|
|
22
|
+
value: Any,
|
|
23
|
+
expire_time: Optional[int] = None,
|
|
24
|
+
tags: Optional[List[str]] = None,
|
|
25
|
+
) -> None: ...
|
|
26
|
+
def delete(self, key: str) -> bool: ...
|
|
27
|
+
def clear(self) -> None: ...
|
|
28
|
+
def exists(self, key: str) -> bool: ...
|
|
29
|
+
def keys(self) -> List[str]: ...
|
|
30
|
+
def size(self) -> int: ...
|
|
31
|
+
def hit_rate(self) -> float: ...
|
|
32
|
+
|
|
33
|
+
class Cache:
|
|
34
|
+
"""Drop-in replacement for diskcache.Cache"""
|
|
35
|
+
def __init__(self, directory: str, **kwargs: Any) -> None: ...
|
|
36
|
+
def __contains__(self, key: str) -> bool: ...
|
|
37
|
+
def __getitem__(self, key: str) -> Any: ...
|
|
38
|
+
def __setitem__(self, key: str, value: Any) -> None: ...
|
|
39
|
+
def __delitem__(self, key: str) -> None: ...
|
|
40
|
+
def __iter__(self) -> typing.Iterator[str]: ...
|
|
41
|
+
def __len__(self) -> int: ...
|
|
42
|
+
def get(self, key: str, default: Any = None, retry: bool = False) -> Any: ...
|
|
43
|
+
def set(
|
|
44
|
+
self,
|
|
45
|
+
key: str,
|
|
46
|
+
value: Any,
|
|
47
|
+
expire: Optional[int] = None,
|
|
48
|
+
read: Optional[bool] = None,
|
|
49
|
+
tag: Optional[str] = None,
|
|
50
|
+
retry: Optional[bool] = None,
|
|
51
|
+
) -> bool: ...
|
|
52
|
+
def add(
|
|
53
|
+
self, key: str, value: Any, expire: Optional[int] = None, retry: bool = False
|
|
54
|
+
) -> bool: ...
|
|
55
|
+
def delete(self, key: str, retry: bool = False) -> bool: ...
|
|
56
|
+
def pop(
|
|
57
|
+
self,
|
|
58
|
+
key: str,
|
|
59
|
+
default: Any = None,
|
|
60
|
+
expire: Optional[int] = None,
|
|
61
|
+
retry: bool = False,
|
|
62
|
+
) -> Any: ...
|
|
63
|
+
def clear(self, retry: bool = False) -> int: ...
|
|
64
|
+
def close(self) -> None: ...
|
|
65
|
+
def exists(self, key: str) -> bool: ...
|
|
66
|
+
def keys(self) -> List[str]: ...
|
|
67
|
+
def values(self) -> List[Any]: ...
|
|
68
|
+
def items(self) -> List[tuple[str, Any]]: ...
|
|
69
|
+
def iterkeys(self) -> typing.Iterator[str]: ...
|
|
70
|
+
def itervalues(self) -> typing.Iterator[Any]: ...
|
|
71
|
+
def iteritems(self) -> typing.Iterator[tuple[str, Any]]: ...
|
|
72
|
+
def expire(self, now: Optional[float] = None) -> int: ...
|
|
73
|
+
def evict(self, tag: Optional[str] = None) -> int: ...
|
|
74
|
+
def stats(self, enable: bool = True, reset: bool = False) -> tuple[int, int]: ...
|
|
75
|
+
def volume(self) -> int: ...
|
|
76
|
+
def reset(self, key: str, value: Any = None) -> None: ...
|
|
77
|
+
def touch(
|
|
78
|
+
self, key: str, expire: Optional[int] = None, retry: bool = False
|
|
79
|
+
) -> bool: ...
|
|
80
|
+
def incr(
|
|
81
|
+
self,
|
|
82
|
+
key: str,
|
|
83
|
+
delta: typing.Union[int, float] = 1,
|
|
84
|
+
default: typing.Union[int, float] = 0,
|
|
85
|
+
retry: bool = False,
|
|
86
|
+
) -> typing.Union[int, float]: ...
|
|
87
|
+
def decr(
|
|
88
|
+
self,
|
|
89
|
+
key: str,
|
|
90
|
+
delta: typing.Union[int, float] = 1,
|
|
91
|
+
default: typing.Union[int, float] = 0,
|
|
92
|
+
retry: bool = False,
|
|
93
|
+
) -> typing.Union[int, float]: ...
|
|
94
|
+
|
|
95
|
+
class FanoutCache:
|
|
96
|
+
"""Drop-in replacement for diskcache.FanoutCache"""
|
|
97
|
+
def __init__(
|
|
98
|
+
self, directory: str, shards: Optional[int] = None, **kwargs: Any
|
|
99
|
+
) -> None: ...
|
|
100
|
+
def __contains__(self, key: str) -> bool: ...
|
|
101
|
+
def __getitem__(self, key: str) -> Any: ...
|
|
102
|
+
def __setitem__(self, key: str, value: Any) -> None: ...
|
|
103
|
+
def __delitem__(self, key: str) -> None: ...
|
|
104
|
+
def __iter__(self) -> typing.Iterator[str]: ...
|
|
105
|
+
def __len__(self) -> int: ...
|
|
106
|
+
def get(self, key: str, default: Any = None, retry: bool = False) -> Any: ...
|
|
107
|
+
def set(
|
|
108
|
+
self,
|
|
109
|
+
key: str,
|
|
110
|
+
value: Any,
|
|
111
|
+
expire: Optional[int] = None,
|
|
112
|
+
read: Optional[bool] = None,
|
|
113
|
+
tag: Optional[str] = None,
|
|
114
|
+
retry: Optional[bool] = None,
|
|
115
|
+
) -> bool: ...
|
|
116
|
+
def delete(self, key: str) -> bool: ...
|
|
117
|
+
def iterkeys(self) -> List[str]: ...
|
|
118
|
+
|
|
119
|
+
class PickleCache:
|
|
120
|
+
"""High-performance pickle cache with expiration support"""
|
|
121
|
+
def __init__(
|
|
122
|
+
self,
|
|
123
|
+
directory: str,
|
|
124
|
+
max_size: Optional[int] = None,
|
|
125
|
+
default_ttl_seconds: Optional[int] = None,
|
|
126
|
+
) -> None: ...
|
|
127
|
+
def set_pickle(
|
|
128
|
+
self, key: str, pickled_data: Any, ttl_seconds: Optional[int] = None
|
|
129
|
+
) -> None: ...
|
|
130
|
+
def get_pickle(self, key: str) -> Optional[bytes]: ...
|
|
131
|
+
def delete(self, key: str) -> bool: ...
|
|
132
|
+
def clear(self) -> None: ...
|
|
133
|
+
def exists(self, key: str) -> bool: ...
|
|
134
|
+
def keys(self) -> List[str]: ...
|
|
135
|
+
def is_expired(self, key: str) -> bool: ...
|
|
136
|
+
def cleanup_expired(self) -> int: ...
|
|
137
|
+
def get_stats(self) -> Dict[str, Any]: ...
|
|
138
|
+
|
|
139
|
+
# Utility Functions
|
|
140
|
+
def detect_diskcache_format_py(path: str) -> bool:
|
|
141
|
+
"""Python wrapper for detect_diskcache_format"""
|
|
142
|
+
...
|
|
143
|
+
|
|
144
|
+
def rust_pickle_dumps(obj: Any) -> Any:
|
|
145
|
+
"""High-performance pickle serialization using Rust"""
|
|
146
|
+
...
|
|
147
|
+
|
|
148
|
+
def rust_pickle_loads(data: Any) -> Any:
|
|
149
|
+
"""High-performance pickle deserialization using Rust"""
|
|
150
|
+
...
|