@@ -59,27 +59,23 @@ For example, if you wanted to to see all URLs requested with a specific method:
5959You can also inspect ` CachedSession.cache.redirects ` , which maps redirect URLs to keys of the
6060responses they redirect to.
6161
62- Additional ` keys() ` and ` values() ` wrapper methods are available on {py: class }` .BaseCache ` to get
63- combined keys and responses.
62+
63+ ### Filtering responses
64+ Use {py: meth }` .BaseCache.filter ` to get responses with optional filters. By default, it returns all
65+ responses except any invalid ones that would raise an exception:
6466``` python
65- >> > print (' All responses:' )
66- >> > for response in session.cache.values():
67+ >> > for response in session.cache.filter():
6768>> > print (response)
68-
69- >> > print (' All cache keys for redirects and responses combined:' )
70- >> > print (list (session.cache.keys()))
7169```
7270
73- Both methods also take a ` check_expiry ` argument to exclude expired responses:
71+ Get unexpired responses:
7472``` python
75- >> > print (' All unexpired responses:' )
76- >> > for response in session.cache.values(check_expiry = True ):
73+ >> > for response in session.cache.filter(expired = False ):
7774>> > print (response)
7875```
7976
80- Similarly, you can get a count of responses with {py: meth }` .BaseCache.response_count ` , and optionally
81- exclude expired responses:
77+ Get keys for ** only** expired responses:
8278``` python
83- >> > print ( f ' Total responses: { session.cache.response_count() } ' )
84- >> > print ( f ' Unexpired responses: { session.cache.response_count( check_expiry = True ) } ' )
79+ >> > expired_responses = session.cache.filter( valid = False , expired = True )
80+ >> > keys = [response.cache_key for response in expired_responses]
8581```
0 commit comments