-
Notifications
You must be signed in to change notification settings - Fork 77
Description
We use cacheback a lot for async 'always fast' fetching of data that is requested regularly. Example: Our API exposes weather info. This data is fetched from a 3rd party vendor API. Occasionally that API has quirks for a certain (usually short) period, which (within certain boundaries of course) we want to hide by returning stale data.
If I understand correctly, once a request is made outside of lifetime but within cache_ttl, the entry stored in cache is replaced by one with ttl of timeout.
So, if request somehow fails, after 'timeout', the cached entry is gone as well, and errors will be visible.
I'd like to elegantly implement a stale-while-error mechanism in Cacheback.
Reference: Similar functionality in Fastly (basically varnish-as-a-service) and Nginx
Haven't looked into implementation but some first thoughts:
- Similar to the
fetch()method that needs to be implemented on a Job subclass, provide a method that can be implemented where errors can be handled.handle_error_while_stale()for example. - If not using a custom Job class, some way to provide a callable that decorates
fetch(), catches errors and re-raises something likeAllowedWhileStaleError
Do you see any value in this?