Add API caching support to rbtools.
Review Request #6504 — Created Oct. 24, 2014 and submitted — Latest diff uploaded
rbtools.api.cachemodule. This module includes the
APICacheclass, which allows the results of
HTTP GETrequests to
be cached locally to achieve faster lookup. The
the following headers:
APICache is backed by a SQLite database in the user's cache
directory. If the cache cannot be accessed, the
APICache will pass
all requests to the specified
urlopen (defaulting to
APICache allows for a custom
urlopen function so that it can
be tested without making actual HTTP requests.
APICache stores the version of its schema in the database. If
APICache is instantiated and the versions of the schema in the
class doesn't match the version of the schema in the database, then
the current cache will be invalidted and the schema will be updated.
Add the ActiveState
appdirs module (at version 1.4.0) as
rbtools.utils.appdirs. This module is used to find the user cache
directory in platform-dependant ways.
rbtools.api.cache.Response class which emulates the
behaviour of a
urllib2 response. This class allows the
method to be called more than once.
rbtools.api.cache.CachedResponse class, which is the result
of a cach entry being found the the
APICache. It also emulates the
behaviour of a
clear-cache command. This command manually clears the API
Added unit tests for the
Unit tests pass.
The following commands were tested and were successful:
Upon clearing the cache with
clear-cache, a new cache is created.
The first run of a command always creates cache entries (where
appropriate, i.e., not for PUT or POST requests).
/api/ endpoint is successfully cached and the cached version is
When using the
patch command for the second time on the same review
request, if the diff has not been updated, then the cached version of
/api/review-requests/<id>/diff/<diff_revision>/ endpoint is
This review request was posted with the