Skip to content

Commit

Permalink
Merge pull request #130 from requests-cache/fix-request-expire-after
Browse files Browse the repository at this point in the history
 Fix TypeError bug when using expire_after param with CachedSession._request()
  • Loading branch information
JWCook committed Jul 13, 2022
2 parents cae3dcb + 72d0452 commit 5c93ad5
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 173 deletions.
6 changes: 6 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# History

## 0.7.2 (2022-07-13)
* Fix `TypeError` bug when using `expire_after` param with `CachedSession._request()`

## 0.7.1 (2022-06-22)
* Use `threading.RLock` for locking `SQLiteCache.init_db()` and `clear()`

## 0.7.0 (2022-05-21)
[See all issues & PRs for v0.7](https://github.com/requests-cache/aiohttp-client-cache/milestone/6?closed=1)
* Support manually saving a response to the cache with `CachedSession.cache.save_response()`
Expand Down
13 changes: 9 additions & 4 deletions aiohttp_client_cache/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
from aiohttp.typedefs import StrOrURL

from aiohttp_client_cache.backends import CacheBackend, get_valid_kwargs
from aiohttp_client_cache.docs import copy_signature, extend_signature
from aiohttp_client_cache.cache_control import ExpirationTime
from aiohttp_client_cache.docs import extend_signature
from aiohttp_client_cache.response import AnyResponse, set_response_defaults

if TYPE_CHECKING:
Expand Down Expand Up @@ -36,11 +37,15 @@ def __init__(
session_kwargs = get_valid_kwargs(super().__init__, {**kwargs, 'base_url': base_url})
super().__init__(**session_kwargs)

@copy_signature(ClientSession._request)
async def _request(self, method: str, str_or_url: StrOrURL, **kwargs) -> AnyResponse:
@extend_signature(ClientSession._request)
async def _request(
self, method: str, str_or_url: StrOrURL, expire_after: ExpirationTime = None, **kwargs
) -> AnyResponse:
"""Wrapper around :py:meth:`.SessionClient._request` that adds caching"""
# Attempt to fetch cached response
response, actions = await self.cache.request(method, str_or_url, **kwargs)
response, actions = await self.cache.request(
method, str_or_url, expire_after=expire_after, **kwargs
)

# Restore any cached cookies to the session
if response:
Expand Down

0 comments on commit 5c93ad5

Please sign in to comment.