Skip to content

Commit a80848f

Browse files
committed
Merge branch 'release/0.5.0'
2 parents 640993f + 33f88ef commit a80848f

File tree

7 files changed

+120
-110
lines changed

7 files changed

+120
-110
lines changed

.vscode/tasks.json

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,6 @@
33
// for the documentation about the tasks.json format
44
"version": "2.0.0",
55
"tasks": [
6-
{
7-
"label": "build",
8-
"type": "shell",
9-
"command": "${command:python.interpreterPath} -m build",
10-
"problemMatcher": [
11-
"$python"
12-
],
13-
"group": {
14-
"kind": "build",
15-
"isDefault": true
16-
}
17-
},
18-
{
19-
"label": "test",
20-
"type": "shell",
21-
"command": "${command:python.interpreterPath} -m unittest",
22-
"problemMatcher": [
23-
"$python"
24-
],
25-
"group": {
26-
"kind": "test",
27-
"isDefault": true
28-
}
29-
},
306
{
317
"label": "docs: build",
328
"type": "shell",

CHANGELOG.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@
22

33
## v0.5
44

5-
> 📅 developing (beta-2)
5+
> 📅 2025-08-26
66
77
-**New Features:**
88
- Added arguments excluding support for the `RedisFuncCache` class, which makes it possible to cache functions with arguments that cannot be serialized.
99
- 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:
1111
- `RedisFuncCache.mode_context()` for applying mode contextually
1212
- `RedisFuncCache.disable_rw()` as an alias for completely disabling cache read and write operations
1313
- `RedisFuncCache.read_only()` for read-only cache mode
1414
- `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.
1616
- Added support for per-invocation's cache TTL(experimental).
17+
- Added `use_bytecode` attribute to `HashConfig` class.
1718

1819
- 💔 **Breaking Changes:**
1920
- Rename `redis_func_cache.mixins.policies` to `redis_func_cache.mixins.scripts`.

README.md

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -948,21 +948,33 @@ def some_func(*args, **kwargs):
948948
949949
- Compatibility with other [decorator][]s is not guaranteed.
950950
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:
952952
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.
958954
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**.
961956
962-
my_cache = RedisFuncCache(__name__, policy=MyLfuPolicy, client=redis_client_factory)
963-
```
957+
- 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):
969+
__key__ = "my-lfu"
970+
971+
# Override hash config here !!!
972+
__hash_config__ = replace(JsonMd5HashMixin.__hash_config__, use_bytecode=False)
973+
974+
cache = Cache(__name__, policy=MyLfuPolicy, client=redis_client_factory)
975+
```
964976
965-
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.
966978
967979
- 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.
968980

docs/README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ How to Build the Documentation
2525

2626
.. code:: sh
2727
28-
sphinx-apidoc -o docs/apidocs -f -e -H APIs src
28+
sphinx-apidoc -H "" -feo docs/apidocs src
2929
3030
#. Build HTML documentation:
3131

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109
"redis": ("https://redis.readthedocs.io/en/stable/", None),
110110
"pymongo": ("https://pymongo.readthedocs.io/en/stable/", None),
111111
"msgpack": ("https://msgpack-python.readthedocs.io/en/stable/", None),
112-
"pygments": ("https://pygments.org/docs/", None),
112+
"pygments": ("https://pygments.org/", None),
113113
}
114114

115115
# -- Options for Napoleon settings ---------------------------------------

0 commit comments

Comments
 (0)