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
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
Copy file name to clipboardExpand all lines: src/redis_func_cache/cache.py
+12-5Lines changed: 12 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -755,17 +755,22 @@ def decorate(
755
755
Note:
756
756
If assigned, it overwrite the :attr:`serializer` property of the cache instance on, and only affect the currently decorated function.
757
757
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.
759
759
760
760
Note:
761
761
This parameter specifies the expiration time for a single invocation result inside the cached structures, not for the entire cache.
762
762
763
763
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.
766
771
767
772
Warning:
768
-
Experimental and only available in Redis versions above 7.4`
773
+
This feature is **experimental** and requires Redis 7.4 or above.
769
774
770
775
.. versionadded:: 0.5
771
776
@@ -989,6 +994,7 @@ def func(): ...
989
994
990
995
991
996
with cache.read_only():
997
+
# `func()` will NOT be executed, result is read from cache, and dose not write to cache
992
998
result = func()
993
999
994
1000
.. versionadded:: 0.5
@@ -1010,7 +1016,8 @@ def func(): ...
1010
1016
1011
1017
1012
1018
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
0 commit comments