[whatwg] Proposal for Web Storage expiration

Paul Ellis paul at ellisfoundation.com
Thu Jul 29 23:57:09 PDT 2010


On Thu, Jul 29, 2010 at 10:57 AM, Nicholas Zakas <nzakas at yahoo-inc.com>wrote:

>      setter creator void setItem(in DOMString key, in any data, [Optional]
> in unsigned long ttl);
>
>
>
> The third argument is a TTL specifying how long, in milliseconds, the data
> should be stored in sessionStorage/localStorage. Some proposed
> implementation details:
>
> * A TTL of 0 is considered invalid and ignored, as is any value less than
> 0. If you want to immediately remove a key, it should be done via
> removeItem().
>
> * The TTL for a key may be changed each time setItem() is called, with the
> new TTL overwriting the old one.
>
> * If a TTL was previously set, and then a new TTL is not provided on a
> subsequent call to setItem(), then the original TTL remains.
>
> * If a TTL was previously set, and another call is made to setItem() that
> contains an invalid TTL (<= 0), then the original TTL remains.
>
> * To remove a previously set TTL, you must call removeItem() to completely
> remove the key and then re-add using setItem().
>
> * Adding a third argument means the length property of setItem will be 3,
> so developers can check for support of this feature using
> (localStorage.setItem.length > 2).
>
> * The TTL is valid for both sessionStorage and localStorage, but more
> important for localStorage.
>
I like this idea. It would help deal with orphaned data that was written by
a site, but was never removed or used after a change in the site.

It seems that there should be a way to change a TTL without having to load
and set the value data again, or remove a TTL without having to remove the
key and re-add it. While it might not be too bad to remove a single key and
re-add it, it becomes a nuisance to remove the TTL on many keys by loading,
removing, and re-adding each key. I'm thinking of scenarios where
localStorage may be used to locally cache data for a user (e.g. an email
client) where the user may have the option to choose to keep the data for 1
week, 1 month, etc. If the user choose to change the caching duration then
the browser may have to load and set 5MB of data, just to update the TTLs.

My thought is that to remove a TTL we could either pass -1 (any negative
number perhaps) to the function to reset the TTL, or use an empty value
(null or ""). To just change a TTL without changing the key/value we may
consider making the second parameter optional as well, although I'm not in
love with that idea.

Paul Ellis
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.whatwg.org/pipermail/whatwg-whatwg.org/attachments/20100729/f4f174be/attachment-0002.htm>


More information about the whatwg mailing list