Skip to content

Commit 5a5ab66

Browse files
committed
docs(redis_func_cache): update documentation for experimental TTL feature
- Add link to Redis hashes field expiration documentation - Clarify that TTL applies to individual invocation results - Update notes on experimental status and Redis version requirement - Improve explanation of HASH field expiration behavior - Document lazy cleanup of ZSET entries after expiration - Enhance code comments for read-only and disable-read contexts
1 parent c80a337 commit 5a5ab66

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,7 @@ The [`RedisFuncCache`][] instance has two arguments to control the maximum size
462462
463463
> ⚠️ **Warning:**\
464464
> This feature is experimental and requires [Redis][] 7.4 or above.
465+
> See [Redis hashes Field expiration](https://redis.io/docs/latest/develop/data-types/hashes/#field-expiration) for more details.
465466
466467
### Complex return types
467468

src/redis_func_cache/cache.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -755,17 +755,22 @@ def decorate(
755755
Note:
756756
If assigned, it overwrite the :attr:`serializer` property of the cache instance on, and only affect the currently decorated function.
757757
758-
ttl: (_Experimental_) The time-to-live (in seconds) for a single invocation.
758+
ttl: (**Experimental**) The time-to-live (in seconds) for a single invocation's result cache.
759759
760760
Note:
761761
This parameter specifies the expiration time for a single invocation result inside the cached structures, not for the entire cache.
762762
763763
Caution:
764-
The expiration is based on [Redis Hashes Field expiration](https://redis.io/docs/latest/develop/data-types/hashes/#field-expiration).
765-
Therefore, expiration only applies to the hash field and does not decrease the total item count in the cache when a field expires.
764+
This experimental expiration mechanism relies on `Redis Hashes Field expiration <https://redis.io/docs/latest/develop/data-types/hashes/#field-expiration)>`_.
765+
Expiration only applies to the `HASH` field (the cached return value), and does **not** reduce the total number of items in the cache when a field expires.
766+
767+
Typically, the cached return value in the `HASH` portion is automatically released after expiration.
768+
However, the corresponding hash key in the `ZSET` portion is **not** removed automatically.
769+
Instead, it is only "lazily" cleaned up when accessed, or removed by the eviction policy when a new value is added.
770+
During this period, the `ZSET` portion continues to occupy memory, and the reported number of cache items does not decrease.
766771
767772
Warning:
768-
Experimental and only available in Redis versions above 7.4`
773+
This feature is **experimental** and requires Redis 7.4 or above.
769774
770775
.. versionadded:: 0.5
771776
@@ -989,6 +994,7 @@ def func(): ...
989994
990995
991996
with cache.read_only():
997+
# `func()` will NOT be executed, result is read from cache, and dose not write to cache
992998
result = func()
993999
9941000
.. versionadded:: 0.5
@@ -1010,7 +1016,8 @@ def func(): ...
10101016
10111017
10121018
with cache.disable_read():
1013-
result = func() # will be executed and result stored in cache, but not read from cache
1019+
# `func()` will be executed and result stored in cache, but not read from cache
1020+
result = func()
10141021
10151022
.. versionadded:: 0.5
10161023
"""

0 commit comments

Comments
 (0)