You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+4-3Lines changed: 4 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,18 +2,19 @@
2
2
3
3
## v0.5
4
4
5
-
> 📅 developing (beta-2)
5
+
> 📅 2025-08-26
6
6
7
7
- ✨ **New Features:**
8
8
- Added arguments excluding support for the `RedisFuncCache` class, which makes it possible to cache functions with arguments that cannot be serialized.
9
9
- Added support for controlling cache TTL update behavior with `update_ttl` parameter.
10
-
- Enhanced cache mode control with context managers:
10
+
- Enhanced cache mode control with mode context managers:
11
11
-`RedisFuncCache.mode_context()` for applying mode contextually
12
12
-`RedisFuncCache.disable_rw()` as an alias for completely disabling cache read and write operations
13
13
-`RedisFuncCache.read_only()` for read-only cache mode
14
14
-`RedisFuncCache.write_only()` for write-only cache mode
15
-
- Added new `RedisFuncCache.Stats` class for cache statistics, and `RedisFuncCache.stats_context()` for retrieving cache statistics.
15
+
- Added new `RedisFuncCache.Stats` class for cache statistics, and `RedisFuncCache.stats_context()` for retrieving cache statistics in a context manager.
16
16
- Added support for per-invocation's cache TTL(experimental).
17
+
- Added `use_bytecode` attribute to `HashConfig` class.
17
18
18
19
- 💔 **Breaking Changes:**
19
20
- Rename `redis_func_cache.mixins.policies` to `redis_func_cache.mixins.scripts`.
- Compatibility with other [decorator][]s is not guaranteed.
950
950
951
-
- The built-in policies in `redis_func_cache.policies` use [`pickle`][] to serialize function arguments, then calculate the cache key by hashing the serialized data with `md5`. [`pickle`][] is chosen because only the hash bytes are stored in Redis, not the serialized data itself, so this is safe. However, [`pickle`][] causes **incompatibility between different Python versions**. If your application needs to be compatible across Python versions, you should use a [json][] based hash mixer, or define your own hash policy using a version-compatible serialization method, for example:
951
+
- It cannot hit cache across different Python versions by default. Because:
952
952
953
-
```python
954
-
from redis_func_cache import RedisFuncCache
955
-
from redis_func_cache.policies.abstract import BaseSinglePolicy
956
-
from redis_func_cache.mixins.hash import JsonMd5HashMixin
957
-
from redis_func_cache.mixins.scripts import LfuScriptsMixin
953
+
- The built-in policies in `policies` use [`pickle`][] to serialize function arguments and then calculate the cache key by hashing the serialized data with `md5` by default.
958
954
959
-
class MyLfuPolicy(LfuScriptsMixin, JsonMd5HashMixin, BaseSinglePolicy):
960
-
__key__ = "my-lfu"
955
+
[`pickle`][] is chosen because only the hash bytes are stored in Redis, not the serialized data itself, making this approach safe. However, [`pickle`][] causes **incompatibility between different Python versions**.
- The key calculation defined in `mixins.hash.AbstractHashMixin.calc_hash()` uses the function's bytecode as part of the hash computation by default. So it cannot hit cache across different Python versions.
958
+
959
+
If your application needs to be compatible across Python versions, you should disable `use_bytecode` attribute of the mixin's `__hash_config__`, and use a [json][] based hash mixer. Or define your own hash policy using a version-compatible serialization method. For example:
960
+
961
+
```python
962
+
from dataclasses import replace
963
+
from redis_func_cache import RedisFuncCache as Cache
964
+
from redis_func_cache.policies.abstract import BaseSinglePolicy
965
+
from redis_func_cache.mixins.hash import JsonMd5HashMixin
966
+
from redis_func_cache.mixins.scripts import LfuScriptsMixin
967
+
968
+
class MyLfuPolicy(LfuScriptsMixin, JsonMd5HashMixin, BaseSinglePolicy):
As shown above, the `JsonMd5HashMixin` uses [json][], which can be used across different Python versions, rather than [`pickle`][].
977
+
As shown above, the `JsonMd5HashMixin` uses [json][], which can be used across different Python versions, rather than [`pickle`][]. `use_bytecode` is set to `False` to avoid version compatible problems caused by bytecode.
966
978
967
979
- The cache eviction policies are mainly based on [Redis][] sorted set's score ordering. For most policies, the score is a positive integer. Its maximum value is `2^32-1`in [Redis][], which limits the number of times of eviction replacement. [Redis][] will return an `overflow` error when the score overflows.
0 commit comments