Skip to content

Commit f03c801

Browse files
committed
docs(cache): improve RedisFuncCache class documentation and add update_ttl property
- Enhance the docstring for the RedisFuncCache class to clarify maxsize, ttl, and update_ttl parameters - Add a new property update_ttl to the RedisFuncCache class - Update the docstring for the set method to reference the new update_ttl property
1 parent d2e9232 commit f03c801

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

src/redis_func_cache/cache.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -172,25 +172,29 @@ def __init__(
172172
173173
maxsize: The maximum size of the cache.
174174
175-
If not provided, the default is :data:`.DEFAULT_MAXSIZE`.
176-
Zero or negative values means no limit.
175+
- If not provided, the default is :data:`.DEFAULT_MAXSIZE`.
176+
- Zero or negative values means no limit.
177+
177178
Assigned to property :attr:`maxsize`.
178179
179-
ttl: The time-to-live (in seconds) for cache items.
180+
ttl: The time-to-live (in seconds) for the whole cache data structures on Redis backend.
181+
182+
- If not provided, the default is :data:`.DEFAULT_TTL`.
183+
- Zero or negative values means no set ttl.
180184
181-
If not provided, the default is :data:`.DEFAULT_TTL`.
182-
Zero or negative values means no set ttl.
183185
Assigned to property :attr:`ttl`.
184186
185-
update_ttl: Whether to update the TTL of cached items when they are accessed.
187+
update_ttl: Whether to update the TTL of the whole cache data structures on Redis backend when they are accessed.
188+
189+
- When ``True`` (default), accessing a cached item will reset its TTL.
190+
- When ``False``, accessing a cached item will not update its TTL.
186191
187-
If not provided, the default is ``True``.
188-
When ``True``, accessing a cached item will reset its TTL.
189-
When ``False``, accessing a cached item will not update its TTL.
192+
Assigned to property :attr:`update_ttl`.
190193
191194
prefix: The prefix for cache keys.
192195
193196
If not provided, the default is :data:`.DEFAULT_PREFIX`.
197+
194198
Assigned to property :attr:`prefix`.
195199
196200
serializer: Optional serialize/deserialize name or function pair for return value of what decorated.
@@ -326,6 +330,15 @@ def ttl(self, value: int):
326330
raise ValueError("ttl must be a greater than 0")
327331
self._ttl = int(value)
328332

333+
@property
334+
def update_ttl(self) -> bool:
335+
"""Whether to update the TTL of cache items."""
336+
return self._update_ttl
337+
338+
@update_ttl.setter
339+
def update_ttl(self, value: bool):
340+
self._update_ttl = bool(value)
341+
329342
@property
330343
def serializer(self) -> SerializerPairT:
331344
"""The serializer and deserializer pair used by the cache.
@@ -745,7 +758,7 @@ def decorate(
745758
746759
update_ttl: Whether to update the TTL of cached items when they are accessed.
747760
748-
- If not provided, the default is the value set in the cache instance.
761+
- If not provided, the default is the value of :attr:`update_ttl`.
749762
- When ``True``, accessing a cached item will reset its TTL.
750763
- When ``False``, accessing a cached item will not update its TTL.
751764

0 commit comments

Comments
 (0)