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
refactor(cache): rename scoped_mode to mode_context
- Updated context manager name from `scoped_mode` to `mode_context` for clarity
- Updated related documentation in README and CHANGELOG
- Renamed function calls and references to use new `mode_context` name
Copy file name to clipboardExpand all lines: CHANGELOG.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,8 +7,8 @@
7
7
- ✨ **New Features:**
8
8
- Added arguments excluding support for the `RedisFuncCache` class, which makes it possible to cache functions with arguments that cannot be serialized.
9
9
- Added support for controlling cache TTL update behavior with `update_ttl` parameter.
10
-
- Enhanced cache mode control with bit-flag based `Mode` enum and new context managers:
11
-
-`mask_mode()` for applying mode masks using bitwise AND operations
10
+
- Enhanced cache mode control with context managers:
11
+
-`mode_context()` for applying mode contextually
12
12
-`disable_rw()` as an alias for completely disabling cache read and write operations
Copy file name to clipboardExpand all lines: README.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -179,7 +179,7 @@ The library guarantees thread safety and concurrency security through the follow
179
179
180
180
1. Contextual State Isolation
181
181
182
-
The [ContextVar](https://docs.python.org/3/library/contextvars.html#contextvars.ContextVar) based `scoped_mode()` context manager and other cache control context managers ensure thread and coroutine isolation. Each thread or async task maintains its own independent state, preventing cross-context interference.
182
+
The [ContextVar](https://docs.python.org/3/library/contextvars.html#contextvars.ContextVar) based `mode_context()` context manager and other cache control context managers ensure thread and coroutine isolation. Each thread or async task maintains its own independent state, preventing cross-context interference.
183
183
184
184
Atomicity is a key feature of this library. All cache operations (both read and write) are implemented using Redis Lua scripts, which are executed atomically by the Redis server. This means that each script runs in its entirety without being interrupted by other operations, ensuring data consistency even under high concurrent load.
185
185
@@ -592,13 +592,13 @@ The `update_ttl` parameter controls the behavior of the cache data structures (s
592
592
593
593
### Cache Mode Control
594
594
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:
595
+
The library provides fine-grained control over cache behavior through the `mode_context()` context manager and convenience methods. You can control whether the cache reads from or writes to Redis using the following flags:
596
596
597
597
- `read` (`bool`): allow read from cache
598
598
- `write` (`bool`): allow write to cache
599
599
- `exec` (`bool`): allow execute function
600
600
601
-
You can use the `scoped_mode()` context manager to explicitly set any mode:
601
+
You can use the `mode_context()` context manager to explicitly set any mode:
602
602
603
603
```python
604
604
from redis_func_cache import RedisFuncCache
@@ -614,20 +614,20 @@ data = get_user_data(123)
614
614
# Bypass cache reading, but still write to cache
615
615
mode = cache.get_mode()
616
616
mode.read = False
617
-
with cache.scoped_mode(mode):
617
+
with cache.mode_context(mode):
618
618
data = get_user_data(123) # Function executed, result stored in cache
619
619
620
620
# Only read from cache, don't execute function or write to cache
621
621
mode = cache.get_mode()
622
622
mode.write = False
623
-
with cache.scoped_mode(mode):
623
+
with cache.mode_context(mode):
624
624
data = get_user_data(123) # Only attempts to read from cache
625
625
626
626
# Disable cache read and write
627
627
mode = cache.get_mode()
628
628
mode.read = False
629
629
mode.write = False
630
-
with cache.scoped_mode(mode):
630
+
with cache.mode_context(mode):
631
631
data = get_user_data(123) # Function executed, no cache interaction
0 commit comments