Skip to content

Commit a0ff354

Browse files
committed
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
1 parent e53eb1f commit a0ff354

File tree

1 file changed

+9
-24
lines changed

1 file changed

+9
-24
lines changed

README.md

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ The [`RedisFuncCache`][] instance has two arguments to control the maximum size
443443
cache = RedisFuncCache("my-cache-5", LruTPolicy, redis_client, ttl=300)
444444
```
445445
446-
- 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.
447447
448448
You can set this argument when decorating a function:
449449
@@ -457,11 +457,11 @@ The [`RedisFuncCache`][] instance has two arguments to control the maximum size
457457
The argument's default value is `None`, which means that the cache item will never expire.
458458
459459
> ⁉️ **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.
462462
463463
> ⚠️ **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.
465465
466466
### Complex return types
467467
@@ -584,34 +584,19 @@ sliding_cache = RedisFuncCache("sliding-cache", LruTPolicy, redis_client, update
584584
fixed_cache = RedisFuncCache("fixed-cache", LruTPolicy, redis_client, update_ttl=False)
585585
```
586586
587-
Or override it at the function level:
588-
589-
```python
590-
cache = RedisFuncCache("my-cache", LruTPolicy, redis_client)
591-
592-
# 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-
603587
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 function results.
604588
605-
> 💡 **Tip:** \
589+
> 💡 **Tip:**\
606590
> Use fixed TTL when you want predictable cache expiration behavior, regardless of how often cached functions are accessed.
607591
> Use sliding TTL when you want frequently accessed cached data to remain in cache longer.
608592
609593
### Cache Mode Control
610594
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:
612596
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
615600
616601
You can use the `scoped_mode()` context manager to explicitly set any mode:
617602

0 commit comments

Comments
 (0)