-
Notifications
You must be signed in to change notification settings - Fork 78
Caching
Steve edited this page Jan 20, 2018
·
5 revisions
Caching is mentioned briefly in Request actions, and more fully in issue #103.
Requests are cached in the cache
attribute of each instance:
page.cache
category.cache
site.cache
The cache attribute contains:
-
query
: the request URL -
info
: information about the request -
response
: the response body asdict
orstr
You can access the cache directly (e.g. page.cache
), or you can use the convenience methods page.query()
, page.info()
, and page.response()
:
>>> page = wptools.page()
>>> page.get()
>>> page.query()
['imageinfo', 'restbase', 'labels', 'parse', 'wikidata', 'query']
>>> page.query('wikidata')
u'https://www.wikidata.org/w/api.php?action=wbgetentities&formatversion=2&languages=en&props=aliases|info|claims|descriptions|labels|sitelinks&redirects=yes&ids=Q1001'
>>> page.info('wikidata')
{'bytes': 102421.0,
'content': 'application/json; charset=utf-8',
'kB/s': '110.5',
'seconds': '0.927',
'status': 200,
'url': 'https://www.wikidata.org/w/api.php?action=wbgetentities&languages=en&props=aliases|info|claims|descriptions|labels|sitelinks&redirects=yes&ids=Q1001',
'user-agent': 'wptools/0.4.8 (https://github.com/siznax/wptools) PycURL/7.43.0.1 libcurl/7.54.0 LibreSSL/2.0.20 zlib/1.2.11 nghttp2/1.24.0'}
>>> page.response('wikidata')
{u'entities': {u'Q1001': {u'aliases': {u'en': [{u'language': u'en',
u'value': u'M K Gandhi'},
{u'language': u'en', u'value': u'Mohandas Gandhi'},
{u'language': u'en', u'value': u'Bapu'},
{u'language': u'en', u'value': u'Gandhi'},
...