treojs / treo

Consistent API to IndexedDB
http://treojs.com
MIT License
258 stars 18 forks source link

Feature: TTL or Auto-expiration #15

Closed beeftornado closed 9 years ago

beeftornado commented 9 years ago

I have some boilerplate code I have to use around my store access to refresh the data after a period of time. Thought it would be nice if it was implemented at a library level. addStore() could accept a ttl parameter, which would be a duration. On put's, an expiration time can be generated and on get's, the expiration time can be checked. If the data has expired it can call a 'generator' function (a callback) to regenerate the data. This is basically what I do now to refresh the cache every day.

alekseykulikov commented 9 years ago

Hi @beeftornado! It's a nice idea for plugin (treo-ttl). You can check example for more information: https://github.com/alekseykulikov/treo/blob/master/examples/find-in-plugin.js

I've added support for store.opts, which you can use in your custom put/get methods, but it's not released yet, because it contains some improvements around transaction management and better schema support, which has not worked in websql yet.

Let me know if I can you more to figure out this feature.

alekseykulikov commented 9 years ago

I hope someone will create a plugin for this idea eventually, close for now