kwvanderlinde / python-cached-requests

Memory-efficient caching for the requests library and Python 3
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Add ETag support #7

Open kwvanderlinde opened 5 years ago

kwvanderlinde commented 5 years ago

The current implementation is not aware of ETag at all, though it naturally stores ETag along with the rest of the headers. The CachedHTTPAdapter should be updated to add an If-None-Match to requests when the current cache entry is stale.

Note that the Cache interface is not sufficient for caches to implement time-based expiry, especially when combined with the desire to use the ETag to validate a stale entry. This is deliberate, as caches should not be altering requests, which is necessary with ETag. Instead, the adapter will check whether the CacheEntry returned by a cache is stale or not, and use the ETag if it is present.

Another option is to enhance the Cache interface. We could add a stale member to CacheEntry to indicate whether the entry is stale or not, as determined by the cache implementation. It would still be up to the adapter to make use of this information properly, and to delete any invalidated entries.

kwvanderlinde commented 5 years ago

Revalidation must also be supported without having to rewrite an existing entry.