diff options
| author | Roman Haritonov <reclosedev@gmail.com> | 2013-01-12 18:59:02 +0400 |
|---|---|---|
| committer | Roman Haritonov <reclosedev@gmail.com> | 2013-01-12 18:59:02 +0400 |
| commit | 1c99310f10984da3f9bdd042dd7dd98dd57de332 (patch) | |
| tree | 03fc9d2d0009f5ae73dafe6f62ffef997c4c810c /requests_cache | |
| parent | c62fc4b5bd7249508750ede7b20b1d1d11a72c18 (diff) | |
| download | requests-cache-1c99310f10984da3f9bdd042dd7dd98dd57de332.tar.gz | |
Rename configure to install_cache and add session_factory parameter
Diffstat (limited to 'requests_cache')
| -rw-r--r-- | requests_cache/__init__.py | 4 | ||||
| -rw-r--r-- | requests_cache/core.py | 27 |
2 files changed, 23 insertions, 8 deletions
diff --git a/requests_cache/__init__.py b/requests_cache/__init__.py index 4708044..4b334da 100644 --- a/requests_cache/__init__.py +++ b/requests_cache/__init__.py @@ -9,7 +9,7 @@ Just write:: import requests_cache - requests_cache.configure() + requests_cache.install_cache() And requests to resources will be cached for faster repeated access:: @@ -26,5 +26,5 @@ __docformat__ = 'restructuredtext' __version__ = '0.3.0' from .core import( - CachedSession, configure, install_cached_session, + CachedSession, install_cache )
\ No newline at end of file diff --git a/requests_cache/core.py b/requests_cache/core.py index ea4599f..ca6158c 100644 --- a/requests_cache/core.py +++ b/requests_cache/core.py @@ -98,9 +98,24 @@ class CachedSession(Session): return response -def install_cached_session(session_factory=CachedSession): - requests.Session = requests.sessions.Session = session_factory - - -def configure(*args, **kwargs): - install_cached_session(lambda : CachedSession(*args, **kwargs)) +def install_cache(cache_name='cache', backend='sqlite', expire_after=None, + allowable_codes=(200,), allowable_methods=('GET',), + session_factory=CachedSession, **backend_options): + """ + Installs cache for all ``Requests`` requests by monkey-patching ``Session`` + + Parameters are the same as in :class:`CachedSession`. + :param session_factory: Session factory. It should inherit CachedSession (default) + """ + _patch_session_factory( + lambda : session_factory(cache_name=cache_name, + backend=backend, + expire_after=expire_after, + allowable_codes=allowable_codes, + allowable_methods=allowable_methods, + **backend_options) + ) + + +def _patch_session_factory(session_factory=CachedSession): + requests.Session = requests.sessions.Session = session_factory
\ No newline at end of file |
