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(README): update cache control explanation and remove function-level override example
- Remove function-level override example for update_ttl
- Clarify that update_ttl affects cache data structures, not individual items
- Update cache mode control section to use flag names instead of modes
- per-invocation TTL: The expiration time (in seconds) for each cached item, not the entire cache.
446
+
- per-invocation TTL: (Experimental) The expiration time (in seconds) for each cached item, not the entire cache.
447
447
448
448
You can set this argument when decorating a function:
449
449
@@ -457,11 +457,11 @@ The [`RedisFuncCache`][] instance has two arguments to control the maximum size
457
457
The argument's default value is `None`, which means that the cache item will never expire.
458
458
459
459
> ⁉️ **Caution:**\
460
-
> This expiration relies on [Redis Hashes Field expiration](https://redis.io/docs/latest/develop/data-types/hashes/#field-expiration). 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.
461
-
> Typically, the cached return value in the HASH portion is automatically released after expiration. However, the corresponding hash key in the ZSET portion is **not** removed automatically. Instead, it is only "lazily" cleaned up when accessed, or removed by the eviction policy when a new value is added. During this period, the ZSET portion continues to occupy memory, and the reported number of cache items does not decrease.
460
+
> This experimental expiration mechanism relies on [Redis Hashes Field expiration](https://redis.io/docs/latest/develop/data-types/hashes/#field-expiration). 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.
461
+
> Typically, the cached return value in the `HASH` portion is automatically released after expiration. However, the corresponding hash key in the `ZSET` portion is **not** removed automatically. Instead, it is only "lazily" cleaned up when accessed, or removed by the eviction policy when a new value is added. During this period, the `ZSET` portion continues to occupy memory, and the reported number of cache items does not decrease.
462
462
463
463
> ⚠️ **Warning:**\
464
-
> This feature requires [Redis][] Open Source version 7.4 or later.
464
+
> This feature is experimental and requires [Redis][] 7.4 or above.
# Override to use fixed TTL for this specific function
593
-
@cache(update_ttl=False)
594
-
def my_func(x):
595
-
...
596
-
597
-
# Override to use sliding TTL for this specific function
598
-
@cache(update_ttl=True)
599
-
def another_func(x):
600
-
...
601
-
```
602
-
603
587
The `update_ttl` parameter controls the behavior of the cache data structures (sorted set and hash map) as a whole, not individual cached items. It is independent of the per-item TTL (set via the `ttl` parameter in the decorator), which controls the expiration of individual cached functionresults.
604
588
605
-
> 💡 **Tip:**\
589
+
> 💡 **Tip:**\
606
590
> Use fixed TTL when you want predictable cache expiration behavior, regardless of how often cached functions are accessed.
607
591
> Use sliding TTL when you want frequently accessed cached data to remain in cache longer.
608
592
609
593
### Cache Mode Control
610
594
611
-
The library provides fine-grained control over cache behavior through the `scoped_mode()` context manager and convenience methods. You can control whether the cache reads from or writes to Redis using the following modes:
595
+
The library provides fine-grained control over cache behavior through the `scoped_mode()` context manager and convenience methods. You can control whether the cache reads from or writes to Redis using the following flags:
612
596
613
-
- `READ`: Only read from cache
614
-
- `WRITE`: Only write to cache
597
+
- `read` (`bool`): allow read from cache
598
+
- `write` (`bool`): allow write to cache
599
+
- `exec` (`bool`): allow execute function
615
600
616
601
You can use the `scoped_mode()` context manager to explicitly set any mode:
0 commit comments