Urlquick II: Requests, but with caching¶
Urlquick 2 is a wrapper for requests that add’s support for http caching. It acts just like requests but with a few extra parameters and features. ‘Requests’ itself is left untouched.
All GET, HEAD and POST requests are cached locally for a period of 4 hours, this can be changed. When the cache expires, conditional headers are added to any new request e.g. “Etag” and “Last-modified”. Then if the server returns a 304 Not-Modified response, the cache is used, saving having to re-download the content body.
All of Requests
request functions/methods all get 2 extra optional parameters.
Both these 2 parameters can also be set on a session object too.
max_age: Age the ‘cache’ can be before it’s considered stale.
raise_for_status: Boolean that when set to
resp.raise_for_status()for you automatically.
The Requests response objects also gets too new methods.
parse(): Parse’s “HTML” document into a element tree using HTMLement.
xml(): Parse’s XML document into a element tree.
The time in seconds where a cache item is considered stale. Stale items will stay in the database to allow for conditional headers.
Location for the cache directory. Defaults to the current working directory.
This class is idendical to the requests RESPONSE class, except for 2 small differences.
Parse’s “HTML” document into a element tree using HTMLement.
The htmlement documentation can be found at.
The root element of the element tree.