Skip to content

Commit

Permalink
add updating_parameters argument in file_cache and afile_cache decora…
Browse files Browse the repository at this point in the history
…tors in http_cache module
  • Loading branch information
User committed Apr 27, 2024
1 parent 8f07d44 commit 48d67b7
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions motleycrew/caсhing/http_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,25 @@ class StrongCacheException(BaseException):
load_dotenv()


def file_cache(http_cache: "BaseHttpCache"):
def file_cache(http_cache: "BaseHttpCache", updating_parameters: dict = {}):
"""Decorator to cache function output based on its inputs, ignoring specified parameters."""

def decorator(func):
def wrapper(*args, **kwargs):
kwargs.update(updating_parameters)
return http_cache.get_response(func, *args, **kwargs)

return wrapper

return decorator


def afile_cache(http_cache: "BaseHttpCache"):
def afile_cache(http_cache: "BaseHttpCache", updating_parameters: dict = {}):
"""Async decorator to cache function output based on its inputs, ignoring specified parameters."""

def decorator(func):
async def wrapper(*args, **kwargs):
kwargs.update(updating_parameters)
return await http_cache.aget_response(func, *args, **kwargs)

return wrapper
Expand Down Expand Up @@ -291,7 +293,7 @@ def prepare_response(self, response: Any) -> Any:
def _enable(self):
"""Replacing the original function with a caching function"""

@file_cache(self)
@file_cache(self, updating_parameters={"stream": False})
def request_func(s, request, *args, **kwargs):
return self.library_method(s, request, **kwargs)

Expand Down

0 comments on commit 48d67b7

Please sign in to comment.