koba04
2017-11-22
When I develop an application, I use WebStorage or IndexedDB to cache API responses. To keep the freshness of the cached API data, I often store the data and expiration time as well as Cookie’s expires. I suppose it’s a common use case to set an expiration time for stored data.
sessionStorage.setItem(
'/some/api',
JSON.stringify({
data: apiResponse,
expires: '2017-11-23 00:00:00'
})
);
Also, I think it would be nice if Cache API had a mechanism to set an expiration time. I might be able to do this using the cache key, but I’d like to set the expiration time per request.
Is there any reason these APIs don’t have expiration time? I understand I can implement an expiration time in user space, but it would be nice if browsers have them.
Thanks!