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(cache): update parameter names for excluding arguments from cache key
- Rename `exclude_positional_args` to `exclude_args_indices`
- Rename `exclude_keyword_args` to `exclude_args_names`
- Update README.md to reflect new parameter names
- Update cache.py to use new parameter names
Copy file name to clipboardExpand all lines: CHANGELOG.md
+3Lines changed: 3 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,6 +7,9 @@
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
10
+
- 💔 **Breaking Changes:**
11
+
- Rename `redis_func_cache.mixins.policies` to `redis_func_cache.mixins.scripts`.
Copy file name to clipboardExpand all lines: README.md
+6-5Lines changed: 6 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -728,7 +728,7 @@ However, you can work around this issue by:
728
728
729
729
- Splitting the functioninto two parts: one with fully serializable arguments (apply the cache decorator to this part), and another that may contain un-serializable arguments (this part calls the first one).
730
730
731
-
- Using `exclude_keyword_args` or `exclude_positional_args` to exclude un-serializable arguments from key and hash calculations.
731
+
- Using `exclude_args_names` or `exclude_args_indices` to exclude un-serializable arguments from key and hash calculations.
732
732
733
733
This approach is particularly useful for functions such as a database query.
734
734
@@ -737,20 +737,21 @@ For example, the `pool` argument in the following function is not serializable:
737
737
```python
738
738
def get_book(pool: ConnectionPool, book_id: int):
739
739
connection = pool.get_connection()
740
-
return connection.execute("SELECT * FROM books WHERE book_id = %s", book_id)
740
+
book = connection.execute("SELECT * FROM books WHERE book_id = %s", book_id).fetchone()
741
+
returnjson.dumps(book.to_dict())
741
742
```
742
743
743
744
However, we can exclude the `pool` argument from the key and hash calculations, so the functioncan be cached:
744
745
745
746
```python
746
-
@cache(exclude_keyword_args=["pool"])
747
+
@cache(exclude_args_names=["pool"])
747
748
def get_book(pool: ConnectionPool, book_id: int):
748
749
...
749
750
```
750
751
751
752
Important:
752
-
- When using the `exclude_keyword_args` parameter, ensure that the argument is passed using keyword way.
753
-
- When using the `exclude_positional_args` parameter, ensure that the argument is passed using positional way.
753
+
- When using the `exclude_args_names` parameter, ensure that the argument is passed in a keyword way.
754
+
- When using the `exclude_args_indices` parameter, ensure that the argument is passed in a positional way.
0 commit comments