diskcache-rs 0.4.3__tar.gz → 0.4.4__tar.gz
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-0.4.3 → diskcache_rs-0.4.4}/.github/actions/setup-diskcache-rs/action.yml +1 -1
- diskcache_rs-0.4.4/.release-please-manifest.json +3 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/CHANGELOG.md +12 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/Cargo.lock +1 -1
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/Cargo.toml +1 -1
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/PKG-INFO +1 -1
- diskcache_rs-0.4.4/examples/special_chars_keys_example.py +107 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/python/diskcache_rs/cache.py +42 -2
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/src/utils.rs +21 -9
- diskcache_rs-0.4.4/tests/test_special_chars_keys.py +182 -0
- diskcache_rs-0.4.3/.release-please-manifest.json +0 -3
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/.github/ISSUE_TEMPLATE/feature_request.md +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/.github/actions/build-and-test/action.yml +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/.github/pull_request_template.md +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/.github/workflows/benchmark.yml +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/.github/workflows/build-abi3.yml +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/.github/workflows/build.yml +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/.github/workflows/ci.yml +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/.github/workflows/release.yml +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/.gitignore +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/.pre-commit-config.yaml +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/API_COMPATIBILITY.md +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/Dockerfile.test +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/LICENSE +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/README.md +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/benchmarks/comprehensive_performance_test.py +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/benchmarks/detailed_profiling.py +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/benchmarks/final_performance_comparison.py +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/benchmarks/high_performance_test.py +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/benchmarks/memory_usage_test.py +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/benchmarks/micro_benchmark.py +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/benchmarks/optimization_validation_test.py +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/benchmarks/performance_comparison.py +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/benchmarks/precise_benchmark.py +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/benchmarks/set_performance_analysis.py +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/docker-compose.test.yml +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/examples/basic_usage.py +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/justfile +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/pyproject.toml +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/python/diskcache_rs/__init__.py +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/python/diskcache_rs/__init__.pyi +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/python/diskcache_rs/_diskcache_rs.pyi +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/python/diskcache_rs/core.py +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/python/diskcache_rs/fast_cache.py +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/python/diskcache_rs/pickle_cache.py +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/python/diskcache_rs/rust_pickle.py +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/release-please-config.json +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/renovate.json +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/scripts/generate_stubs.py +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/scripts/sync_version.py +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/scripts/test-docker-network.sh +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/src/cache.rs +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/src/error.rs +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/src/eviction.rs +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/src/lib.rs +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/src/memory_cache.rs +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/src/migration.rs +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/src/pickle_cache.rs +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/src/serialization.rs +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/src/storage/optimized_backend.rs +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/src/storage/tests.rs +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/src/storage.rs +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/tests/__init__.py +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/tests/benchmark_official.py +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/tests/conftest.py +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/tests/test_api_compatibility.py +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/tests/test_basic_operations.py +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/tests/test_ci_benchmark.py +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/tests/test_compatibility.py +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/tests/test_cross_platform_network.py +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/tests/test_diskcache_rs_persistence_suite.py +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/tests/test_docker_network.py +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/tests/test_fast_cache.py +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/tests/test_issue_17_configurable_threshold.py +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/tests/test_network_filesystem.py +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/tests/test_performance.py +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/tests/test_pickle_cache.py +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/tests/test_rust_pickle_performance.py +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/tests/test_version_and_disk_threshold.py +0 -0
- {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/uv.lock +0 -0
|
@@ -36,7 +36,7 @@ runs:
|
|
|
36
36
|
~/.cargo/registry/cache/
|
|
37
37
|
~/.cargo/git/db/
|
|
38
38
|
target/
|
|
39
|
-
key: ${{ runner.os }}-cargo-${{ inputs.cache-key-suffix }}-${{ hashFiles('
|
|
39
|
+
key: ${{ runner.os }}-cargo-${{ inputs.cache-key-suffix }}-${{ hashFiles('Cargo.lock') }}
|
|
40
40
|
restore-keys: |
|
|
41
41
|
${{ runner.os }}-cargo-${{ inputs.cache-key-suffix }}-
|
|
42
42
|
${{ runner.os }}-cargo-
|
|
@@ -4,6 +4,18 @@
|
|
|
4
4
|
|
|
5
5
|
- sync Cargo.toml version with .cz.toml and update CHANGELOG for v0.4.0
|
|
6
6
|
|
|
7
|
+
## [0.4.4](https://github.com/loonghao/diskcache_rs/compare/diskcache_rs-v0.4.3...diskcache_rs-v0.4.4) (2025-11-22)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Features
|
|
11
|
+
|
|
12
|
+
* support special characters in cache keys and auto-deserialization ([e56ad93](https://github.com/loonghao/diskcache_rs/commit/e56ad939b1c95456929d46887441c8d8610f1476))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Bug Fixes
|
|
16
|
+
|
|
17
|
+
* resolve hashFiles path issue in GitHub Actions for macOS ([08abc64](https://github.com/loonghao/diskcache_rs/commit/08abc6442b2c7208b26038f28be07ab31dbccbe7))
|
|
18
|
+
|
|
7
19
|
## [0.4.3](https://github.com/loonghao/diskcache_rs/compare/diskcache_rs-v0.4.2...diskcache_rs-v0.4.3) (2025-11-22)
|
|
8
20
|
|
|
9
21
|
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Example demonstrating support for special characters in cache keys
|
|
3
|
+
|
|
4
|
+
This example shows how diskcache_rs now supports keys containing
|
|
5
|
+
special characters like :, /, \\, . and more.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import tempfile
|
|
9
|
+
from diskcache_rs import Cache
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def main():
|
|
13
|
+
# Create a temporary cache directory
|
|
14
|
+
with tempfile.TemporaryDirectory() as tmpdir:
|
|
15
|
+
cache = Cache(tmpdir)
|
|
16
|
+
|
|
17
|
+
print("=" * 60)
|
|
18
|
+
print("diskcache_rs - Special Characters in Keys Support")
|
|
19
|
+
print("=" * 60)
|
|
20
|
+
print()
|
|
21
|
+
|
|
22
|
+
# Example 1: URL as cache key
|
|
23
|
+
print("1. Using URLs as cache keys:")
|
|
24
|
+
url = "https://api.example.com/v1/users/123?include=profile"
|
|
25
|
+
response_data = {
|
|
26
|
+
"user_id": 123,
|
|
27
|
+
"name": "John Doe",
|
|
28
|
+
"email": "john@example.com"
|
|
29
|
+
}
|
|
30
|
+
cache.set(url, response_data)
|
|
31
|
+
print(f" Key: {url}")
|
|
32
|
+
print(f" Value: {cache.get(url)}")
|
|
33
|
+
print()
|
|
34
|
+
|
|
35
|
+
# Example 2: Namespace with colons
|
|
36
|
+
print("2. Using namespace notation with colons:")
|
|
37
|
+
key = "app:config:database:host"
|
|
38
|
+
value = "localhost:5432"
|
|
39
|
+
cache.set(key, value)
|
|
40
|
+
print(f" Key: {key}")
|
|
41
|
+
print(f" Value: {cache.get(key)}")
|
|
42
|
+
print()
|
|
43
|
+
|
|
44
|
+
# Example 3: File paths as keys
|
|
45
|
+
print("3. Using file paths as keys:")
|
|
46
|
+
windows_path = "C:\\Users\\Admin\\Documents\\file.txt"
|
|
47
|
+
unix_path = "/home/user/documents/file.txt"
|
|
48
|
+
cache.set(windows_path, "Windows file content")
|
|
49
|
+
cache.set(unix_path, "Unix file content")
|
|
50
|
+
print(f" Windows path: {windows_path}")
|
|
51
|
+
print(f" Value: {cache.get(windows_path)}")
|
|
52
|
+
print(f" Unix path: {unix_path}")
|
|
53
|
+
print(f" Value: {cache.get(unix_path)}")
|
|
54
|
+
print()
|
|
55
|
+
|
|
56
|
+
# Example 4: Dot notation (config keys)
|
|
57
|
+
print("4. Using dot notation for configuration:")
|
|
58
|
+
config_keys = {
|
|
59
|
+
"app.name": "MyApp",
|
|
60
|
+
"app.version": "1.0.0",
|
|
61
|
+
"database.host": "localhost",
|
|
62
|
+
"database.port": 5432,
|
|
63
|
+
}
|
|
64
|
+
for key, value in config_keys.items():
|
|
65
|
+
cache.set(key, value)
|
|
66
|
+
print(f" {key} = {cache.get(key)}")
|
|
67
|
+
print()
|
|
68
|
+
|
|
69
|
+
# Example 5: Mixed special characters
|
|
70
|
+
print("5. Complex keys with multiple special characters:")
|
|
71
|
+
complex_keys = [
|
|
72
|
+
"user@domain.com:session:2024-01-01",
|
|
73
|
+
"file://server/share/path/to/file.txt",
|
|
74
|
+
"redis://localhost:6379/0",
|
|
75
|
+
]
|
|
76
|
+
for i, key in enumerate(complex_keys):
|
|
77
|
+
cache.set(key, f"value_{i}")
|
|
78
|
+
print(f" Key: {key}")
|
|
79
|
+
print(f" Value: {cache.get(key)}")
|
|
80
|
+
print()
|
|
81
|
+
|
|
82
|
+
# Example 6: Auto-deserialization
|
|
83
|
+
print("6. Auto-deserialization support:")
|
|
84
|
+
|
|
85
|
+
# Store Python objects (automatically pickled)
|
|
86
|
+
cache.set("python_dict", {"nested": {"data": [1, 2, 3]}})
|
|
87
|
+
print(f" Python dict: {cache.get('python_dict')}")
|
|
88
|
+
|
|
89
|
+
# Store JSON data (automatically detected and parsed)
|
|
90
|
+
import json
|
|
91
|
+
json_bytes = json.dumps({"type": "json", "value": 42}).encode('utf-8')
|
|
92
|
+
cache._cache.set("json_data", json_bytes, expire_time=None, tags=[])
|
|
93
|
+
print(f" JSON data: {cache.get('json_data')}")
|
|
94
|
+
|
|
95
|
+
# Store plain text (automatically decoded)
|
|
96
|
+
text_bytes = "Hello, World!".encode('utf-8')
|
|
97
|
+
cache._cache.set("text_data", text_bytes, expire_time=None, tags=[])
|
|
98
|
+
print(f" Text data: {cache.get('text_data')}")
|
|
99
|
+
print()
|
|
100
|
+
|
|
101
|
+
print("=" * 60)
|
|
102
|
+
print("All examples completed successfully!")
|
|
103
|
+
print("=" * 60)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
if __name__ == "__main__":
|
|
107
|
+
main()
|
|
@@ -4,6 +4,7 @@ Python-compatible cache interface for diskcache_rs
|
|
|
4
4
|
|
|
5
5
|
import functools
|
|
6
6
|
import hashlib
|
|
7
|
+
import json
|
|
7
8
|
import os
|
|
8
9
|
import threading
|
|
9
10
|
import time
|
|
@@ -136,6 +137,45 @@ class Cache:
|
|
|
136
137
|
except Exception:
|
|
137
138
|
return False
|
|
138
139
|
|
|
140
|
+
def _auto_deserialize(self, data: bytes) -> Any:
|
|
141
|
+
"""
|
|
142
|
+
Auto-detect and deserialize data from various formats
|
|
143
|
+
|
|
144
|
+
Tries to deserialize in the following order:
|
|
145
|
+
1. Pickle (most common for diskcache)
|
|
146
|
+
2. JSON (if data looks like JSON)
|
|
147
|
+
3. Raw bytes (if all else fails)
|
|
148
|
+
|
|
149
|
+
Args:
|
|
150
|
+
data: Serialized data bytes
|
|
151
|
+
|
|
152
|
+
Returns:
|
|
153
|
+
Deserialized value
|
|
154
|
+
"""
|
|
155
|
+
# Try pickle first (most common)
|
|
156
|
+
try:
|
|
157
|
+
return pickle.loads(data)
|
|
158
|
+
except Exception:
|
|
159
|
+
pass
|
|
160
|
+
|
|
161
|
+
# Try JSON if it looks like JSON
|
|
162
|
+
try:
|
|
163
|
+
# Check if data starts with common JSON markers
|
|
164
|
+
if data and data[0:1] in (b'{', b'[', b'"'):
|
|
165
|
+
text = data.decode('utf-8')
|
|
166
|
+
return json.loads(text)
|
|
167
|
+
except Exception:
|
|
168
|
+
pass
|
|
169
|
+
|
|
170
|
+
# Try plain text
|
|
171
|
+
try:
|
|
172
|
+
return data.decode('utf-8')
|
|
173
|
+
except Exception:
|
|
174
|
+
pass
|
|
175
|
+
|
|
176
|
+
# Return raw bytes as last resort
|
|
177
|
+
return data
|
|
178
|
+
|
|
139
179
|
def get(
|
|
140
180
|
self,
|
|
141
181
|
key: str,
|
|
@@ -164,8 +204,8 @@ class Cache:
|
|
|
164
204
|
if serialized_value is None:
|
|
165
205
|
return default
|
|
166
206
|
|
|
167
|
-
#
|
|
168
|
-
value =
|
|
207
|
+
# Auto-detect and deserialize the value
|
|
208
|
+
value = self._auto_deserialize(serialized_value)
|
|
169
209
|
|
|
170
210
|
# Handle additional return values
|
|
171
211
|
if expire_time or tag:
|
|
@@ -51,17 +51,19 @@ pub fn validate_key(key: &str) -> CacheResult<()> {
|
|
|
51
51
|
return Err(CacheError::InvalidConfig("Key cannot be empty".to_string()));
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
// Increased limit since we use hash-based filenames
|
|
55
|
+
// The actual key can be longer as it's not directly used as filename
|
|
56
|
+
if key.len() > 4096 {
|
|
55
57
|
return Err(CacheError::InvalidConfig(
|
|
56
|
-
"Key too long (max
|
|
58
|
+
"Key too long (max 4096 characters)".to_string(),
|
|
57
59
|
));
|
|
58
60
|
}
|
|
59
61
|
|
|
60
|
-
//
|
|
61
|
-
|
|
62
|
-
if key.
|
|
62
|
+
// Only check for null character which is truly invalid in all contexts
|
|
63
|
+
// Special characters like :, /, etc. are now allowed since we use hash-based filenames
|
|
64
|
+
if key.contains('\0') {
|
|
63
65
|
return Err(CacheError::InvalidConfig(
|
|
64
|
-
"Key contains
|
|
66
|
+
"Key contains null character".to_string(),
|
|
65
67
|
));
|
|
66
68
|
}
|
|
67
69
|
|
|
@@ -278,10 +280,20 @@ mod tests {
|
|
|
278
280
|
|
|
279
281
|
#[test]
|
|
280
282
|
fn test_validate_key() {
|
|
283
|
+
// Valid keys
|
|
281
284
|
assert!(validate_key("valid_key").is_ok());
|
|
282
|
-
assert!(validate_key("").
|
|
283
|
-
assert!(validate_key("key
|
|
284
|
-
assert!(validate_key(
|
|
285
|
+
assert!(validate_key("key/with/slash").is_ok()); // Now allowed
|
|
286
|
+
assert!(validate_key("key:with:colon").is_ok()); // Now allowed
|
|
287
|
+
assert!(validate_key("key\\with\\backslash").is_ok()); // Now allowed
|
|
288
|
+
assert!(validate_key("key.with.dot").is_ok()); // Dot is allowed
|
|
289
|
+
assert!(validate_key("config.app.settings").is_ok()); // Multiple dots
|
|
290
|
+
assert!(validate_key("file.name.txt").is_ok()); // File extensions
|
|
291
|
+
assert!(validate_key("http://example.com/path").is_ok()); // URLs
|
|
292
|
+
|
|
293
|
+
// Invalid keys
|
|
294
|
+
assert!(validate_key("").is_err()); // Empty key
|
|
295
|
+
assert!(validate_key("key\0with\0null").is_err()); // Null character
|
|
296
|
+
assert!(validate_key(&"x".repeat(5000)).is_err()); // Too long (>4096)
|
|
285
297
|
}
|
|
286
298
|
|
|
287
299
|
#[test]
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Test support for special characters in cache keys
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
import pickle
|
|
7
|
+
import tempfile
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
import pytest
|
|
11
|
+
|
|
12
|
+
from diskcache_rs import Cache
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class TestSpecialCharKeys:
|
|
16
|
+
"""Test cache with special characters in keys"""
|
|
17
|
+
|
|
18
|
+
def test_key_with_colon(self):
|
|
19
|
+
"""Test keys containing colon character"""
|
|
20
|
+
with tempfile.TemporaryDirectory() as tmpdir:
|
|
21
|
+
cache = Cache(tmpdir)
|
|
22
|
+
|
|
23
|
+
# Test with colon in key
|
|
24
|
+
key = "namespace:user:123"
|
|
25
|
+
value = {"user_id": 123, "name": "test"}
|
|
26
|
+
|
|
27
|
+
cache.set(key, value)
|
|
28
|
+
result = cache.get(key)
|
|
29
|
+
|
|
30
|
+
assert result == value
|
|
31
|
+
assert key in cache
|
|
32
|
+
|
|
33
|
+
def test_key_with_slash(self):
|
|
34
|
+
"""Test keys containing forward slash"""
|
|
35
|
+
with tempfile.TemporaryDirectory() as tmpdir:
|
|
36
|
+
cache = Cache(tmpdir)
|
|
37
|
+
|
|
38
|
+
# Test with slash in key
|
|
39
|
+
key = "path/to/resource"
|
|
40
|
+
value = "resource_data"
|
|
41
|
+
|
|
42
|
+
cache.set(key, value)
|
|
43
|
+
result = cache.get(key)
|
|
44
|
+
|
|
45
|
+
assert result == value
|
|
46
|
+
assert key in cache
|
|
47
|
+
|
|
48
|
+
def test_key_with_backslash(self):
|
|
49
|
+
"""Test keys containing backslash"""
|
|
50
|
+
with tempfile.TemporaryDirectory() as tmpdir:
|
|
51
|
+
cache = Cache(tmpdir)
|
|
52
|
+
|
|
53
|
+
# Test with backslash in key (Windows path style)
|
|
54
|
+
key = "C:\\Users\\test\\file.txt"
|
|
55
|
+
value = "file_content"
|
|
56
|
+
|
|
57
|
+
cache.set(key, value)
|
|
58
|
+
result = cache.get(key)
|
|
59
|
+
|
|
60
|
+
assert result == value
|
|
61
|
+
assert key in cache
|
|
62
|
+
|
|
63
|
+
def test_key_with_dot(self):
|
|
64
|
+
"""Test keys containing dot character"""
|
|
65
|
+
with tempfile.TemporaryDirectory() as tmpdir:
|
|
66
|
+
cache = Cache(tmpdir)
|
|
67
|
+
|
|
68
|
+
# Test with dot in key
|
|
69
|
+
key = "config.database.host"
|
|
70
|
+
value = "localhost"
|
|
71
|
+
|
|
72
|
+
cache.set(key, value)
|
|
73
|
+
result = cache.get(key)
|
|
74
|
+
|
|
75
|
+
assert result == value
|
|
76
|
+
assert key in cache
|
|
77
|
+
|
|
78
|
+
def test_key_with_multiple_special_chars(self):
|
|
79
|
+
"""Test keys with multiple special characters"""
|
|
80
|
+
with tempfile.TemporaryDirectory() as tmpdir:
|
|
81
|
+
cache = Cache(tmpdir)
|
|
82
|
+
|
|
83
|
+
# Test with multiple special characters
|
|
84
|
+
test_keys = [
|
|
85
|
+
"http://example.com/path?query=1",
|
|
86
|
+
"user@domain.com:password",
|
|
87
|
+
"file://C:\\path\\to\\file",
|
|
88
|
+
"key:with:many:colons",
|
|
89
|
+
"path/with/many/slashes",
|
|
90
|
+
"mixed:path/with\\all",
|
|
91
|
+
"config.app.settings", # dot notation
|
|
92
|
+
"file.name.with.dots.txt", # multiple dots
|
|
93
|
+
]
|
|
94
|
+
|
|
95
|
+
for i, key in enumerate(test_keys):
|
|
96
|
+
value = f"value_{i}"
|
|
97
|
+
cache.set(key, value)
|
|
98
|
+
result = cache.get(key)
|
|
99
|
+
assert result == value, f"Failed for key: {key}"
|
|
100
|
+
assert key in cache
|
|
101
|
+
|
|
102
|
+
def test_url_as_key(self):
|
|
103
|
+
"""Test using URLs as cache keys"""
|
|
104
|
+
with tempfile.TemporaryDirectory() as tmpdir:
|
|
105
|
+
cache = Cache(tmpdir)
|
|
106
|
+
|
|
107
|
+
# Test with full URL
|
|
108
|
+
url = "https://api.example.com/v1/users/123?include=profile&format=json"
|
|
109
|
+
response_data = {
|
|
110
|
+
"user_id": 123,
|
|
111
|
+
"name": "John Doe",
|
|
112
|
+
"email": "john@example.com"
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
cache.set(url, response_data)
|
|
116
|
+
result = cache.get(url)
|
|
117
|
+
|
|
118
|
+
assert result == response_data
|
|
119
|
+
assert url in cache
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
class TestAutoDeserialization:
|
|
123
|
+
"""Test automatic deserialization of different formats"""
|
|
124
|
+
|
|
125
|
+
def test_pickle_deserialization(self):
|
|
126
|
+
"""Test automatic pickle deserialization"""
|
|
127
|
+
with tempfile.TemporaryDirectory() as tmpdir:
|
|
128
|
+
cache = Cache(tmpdir)
|
|
129
|
+
|
|
130
|
+
# Store complex Python object
|
|
131
|
+
value = {"list": [1, 2, 3], "dict": {"nested": True}, "tuple": (1, 2)}
|
|
132
|
+
cache.set("test_key", value)
|
|
133
|
+
result = cache.get("test_key")
|
|
134
|
+
|
|
135
|
+
assert result == value
|
|
136
|
+
|
|
137
|
+
def test_json_deserialization(self):
|
|
138
|
+
"""Test automatic JSON deserialization"""
|
|
139
|
+
with tempfile.TemporaryDirectory() as tmpdir:
|
|
140
|
+
cache = Cache(tmpdir)
|
|
141
|
+
|
|
142
|
+
# Manually store JSON data
|
|
143
|
+
json_data = {"key": "value", "number": 42}
|
|
144
|
+
json_bytes = json.dumps(json_data).encode('utf-8')
|
|
145
|
+
|
|
146
|
+
# Use internal Rust cache to store raw JSON
|
|
147
|
+
cache._cache.set("json_key", json_bytes, expire_time=None, tags=[])
|
|
148
|
+
|
|
149
|
+
# Should auto-deserialize JSON
|
|
150
|
+
result = cache.get("json_key")
|
|
151
|
+
assert result == json_data
|
|
152
|
+
|
|
153
|
+
def test_text_deserialization(self):
|
|
154
|
+
"""Test automatic text deserialization"""
|
|
155
|
+
with tempfile.TemporaryDirectory() as tmpdir:
|
|
156
|
+
cache = Cache(tmpdir)
|
|
157
|
+
|
|
158
|
+
# Store plain text
|
|
159
|
+
text = "Hello, World!"
|
|
160
|
+
text_bytes = text.encode('utf-8')
|
|
161
|
+
|
|
162
|
+
# Use internal Rust cache to store raw text
|
|
163
|
+
cache._cache.set("text_key", text_bytes, expire_time=None, tags=[])
|
|
164
|
+
|
|
165
|
+
# Should auto-deserialize to text
|
|
166
|
+
result = cache.get("text_key")
|
|
167
|
+
assert result == text
|
|
168
|
+
|
|
169
|
+
def test_mixed_formats(self):
|
|
170
|
+
"""Test cache with mixed serialization formats"""
|
|
171
|
+
with tempfile.TemporaryDirectory() as tmpdir:
|
|
172
|
+
cache = Cache(tmpdir)
|
|
173
|
+
|
|
174
|
+
# Store different formats
|
|
175
|
+
cache.set("pickle_key", {"type": "pickle"})
|
|
176
|
+
cache._cache.set("json_key", b'{"type": "json"}', expire_time=None, tags=[])
|
|
177
|
+
cache._cache.set("text_key", b"plain text", expire_time=None, tags=[])
|
|
178
|
+
|
|
179
|
+
# All should deserialize correctly
|
|
180
|
+
assert cache.get("pickle_key") == {"type": "pickle"}
|
|
181
|
+
assert cache.get("json_key") == {"type": "json"}
|
|
182
|
+
assert cache.get("text_key") == "plain text"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|