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.
Files changed (81) hide show
  1. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/.github/actions/setup-diskcache-rs/action.yml +1 -1
  2. diskcache_rs-0.4.4/.release-please-manifest.json +3 -0
  3. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/CHANGELOG.md +12 -0
  4. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/Cargo.lock +1 -1
  5. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/Cargo.toml +1 -1
  6. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/PKG-INFO +1 -1
  7. diskcache_rs-0.4.4/examples/special_chars_keys_example.py +107 -0
  8. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/python/diskcache_rs/cache.py +42 -2
  9. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/src/utils.rs +21 -9
  10. diskcache_rs-0.4.4/tests/test_special_chars_keys.py +182 -0
  11. diskcache_rs-0.4.3/.release-please-manifest.json +0 -3
  12. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
  13. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/.github/ISSUE_TEMPLATE/feature_request.md +0 -0
  14. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/.github/actions/build-and-test/action.yml +0 -0
  15. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/.github/pull_request_template.md +0 -0
  16. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/.github/workflows/benchmark.yml +0 -0
  17. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/.github/workflows/build-abi3.yml +0 -0
  18. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/.github/workflows/build.yml +0 -0
  19. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/.github/workflows/ci.yml +0 -0
  20. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/.github/workflows/release.yml +0 -0
  21. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/.gitignore +0 -0
  22. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/.pre-commit-config.yaml +0 -0
  23. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/API_COMPATIBILITY.md +0 -0
  24. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/Dockerfile.test +0 -0
  25. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/LICENSE +0 -0
  26. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/README.md +0 -0
  27. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/benchmarks/comprehensive_performance_test.py +0 -0
  28. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/benchmarks/detailed_profiling.py +0 -0
  29. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/benchmarks/final_performance_comparison.py +0 -0
  30. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/benchmarks/high_performance_test.py +0 -0
  31. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/benchmarks/memory_usage_test.py +0 -0
  32. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/benchmarks/micro_benchmark.py +0 -0
  33. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/benchmarks/optimization_validation_test.py +0 -0
  34. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/benchmarks/performance_comparison.py +0 -0
  35. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/benchmarks/precise_benchmark.py +0 -0
  36. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/benchmarks/set_performance_analysis.py +0 -0
  37. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/docker-compose.test.yml +0 -0
  38. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/examples/basic_usage.py +0 -0
  39. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/justfile +0 -0
  40. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/pyproject.toml +0 -0
  41. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/python/diskcache_rs/__init__.py +0 -0
  42. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/python/diskcache_rs/__init__.pyi +0 -0
  43. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/python/diskcache_rs/_diskcache_rs.pyi +0 -0
  44. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/python/diskcache_rs/core.py +0 -0
  45. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/python/diskcache_rs/fast_cache.py +0 -0
  46. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/python/diskcache_rs/pickle_cache.py +0 -0
  47. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/python/diskcache_rs/rust_pickle.py +0 -0
  48. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/release-please-config.json +0 -0
  49. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/renovate.json +0 -0
  50. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/scripts/generate_stubs.py +0 -0
  51. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/scripts/sync_version.py +0 -0
  52. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/scripts/test-docker-network.sh +0 -0
  53. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/src/cache.rs +0 -0
  54. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/src/error.rs +0 -0
  55. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/src/eviction.rs +0 -0
  56. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/src/lib.rs +0 -0
  57. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/src/memory_cache.rs +0 -0
  58. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/src/migration.rs +0 -0
  59. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/src/pickle_cache.rs +0 -0
  60. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/src/serialization.rs +0 -0
  61. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/src/storage/optimized_backend.rs +0 -0
  62. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/src/storage/tests.rs +0 -0
  63. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/src/storage.rs +0 -0
  64. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/tests/__init__.py +0 -0
  65. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/tests/benchmark_official.py +0 -0
  66. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/tests/conftest.py +0 -0
  67. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/tests/test_api_compatibility.py +0 -0
  68. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/tests/test_basic_operations.py +0 -0
  69. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/tests/test_ci_benchmark.py +0 -0
  70. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/tests/test_compatibility.py +0 -0
  71. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/tests/test_cross_platform_network.py +0 -0
  72. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/tests/test_diskcache_rs_persistence_suite.py +0 -0
  73. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/tests/test_docker_network.py +0 -0
  74. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/tests/test_fast_cache.py +0 -0
  75. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/tests/test_issue_17_configurable_threshold.py +0 -0
  76. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/tests/test_network_filesystem.py +0 -0
  77. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/tests/test_performance.py +0 -0
  78. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/tests/test_pickle_cache.py +0 -0
  79. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/tests/test_rust_pickle_performance.py +0 -0
  80. {diskcache_rs-0.4.3 → diskcache_rs-0.4.4}/tests/test_version_and_disk_threshold.py +0 -0
  81. {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('**/Cargo.lock') }}
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-
@@ -0,0 +1,3 @@
1
+ {
2
+ ".": "0.4.4"
3
+ }
@@ -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
 
@@ -236,7 +236,7 @@ dependencies = [
236
236
 
237
237
  [[package]]
238
238
  name = "diskcache_rs"
239
- version = "0.4.3"
239
+ version = "0.4.4"
240
240
  dependencies = [
241
241
  "anyhow",
242
242
  "bincode",
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "diskcache_rs"
3
- version = "0.4.3"
3
+ version = "0.4.4"
4
4
  edition = "2021"
5
5
  authors = ["longhao <hal.long@outlook.com>"]
6
6
  description = "A high-performance disk cache implementation in Rust with Python bindings"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: diskcache_rs
3
- Version: 0.4.3
3
+ Version: 0.4.4
4
4
  Classifier: Development Status :: 4 - Beta
5
5
  Classifier: Intended Audience :: Developers
6
6
  Classifier: License :: OSI Approved :: Apache Software License
@@ -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
- # Deserialize the value
168
- value = pickle.loads(serialized_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
- if key.len() > 250 {
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 250 characters)".to_string(),
58
+ "Key too long (max 4096 characters)".to_string(),
57
59
  ));
58
60
  }
59
61
 
60
- // Check for invalid characters that might cause filesystem issues
61
- let invalid_chars = ['/', '\\', ':', '*', '?', '"', '<', '>', '|', '\0'];
62
- if key.chars().any(|c| invalid_chars.contains(&c)) {
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 invalid characters".to_string(),
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("").is_err());
283
- assert!(validate_key("key/with/slash").is_err());
284
- assert!(validate_key(&"x".repeat(300)).is_err());
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"
@@ -1,3 +0,0 @@
1
- {
2
- ".": "0.4.3"
3
- }
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