making localstorage expire?

making localstorage expire?

max4evermax4ever Posts: 45Questions: 0Answers: 0
edited October 2012 in DataTables 1.9
I was having problems with a column bVisible not being applied, then i cleared localstorage and it worked. I am wondering how to make the user's browsers clear their localStorage data when i commit the changes to the production web site. Since it looks like it never expires http://stackoverflow.com/questions/2326943/when-do-items-in-html5-local-storage-expire

I was thinking maybe adding the current month in the key of the item, this way each month the settings would be refreshed? But that would leave a lot of old junk on the browsers(probably negligible to performance ?)

This is my code

[code]
oTable = $('#visualizzazione').dataTable(
{
"fnStateSave": function (oSettings, oData) {
localStorage.setItem( 'DataTables_'+window.location.pathname+$('div.login span:eq(0)').text().split(' ').join('')+"1",JSON.stringify(oData) );
},

"fnStateLoad": function (oSettings) {
return JSON.parse( localStorage.getItem('DataTables_'+window.location.pathname + $('div.login span:eq(0)').text().split(' ').join('')+"1") );
},


....
[/code]

Replies

  • allanallan Posts: 63,394Questions: 1Answers: 10,451 Site admin
    The information stored for the state also includes the time when the state was saved in the `iCreate` parameter of the object. That could be used to not load the state if it is found to be past a certain duration.

    I'm thinking of making localStorage the default storage method for DataTables 1.10 (not quite 100% certain I will yet, but likely), and this will implement exactly that kind of method.

    Allan
  • Arka3LArka3L Posts: 3Questions: 0Answers: 0
    localStorage is a great asset to have at your finger tips however be aware that at anytime if another script calls .clear(); it will wipe all your localStorage data. We're using it for iBooks development to store widget information for later use. Very handy tool.
  • allanallan Posts: 63,394Questions: 1Answers: 10,451 Site admin
    Nice tip - thanks. I'll certainly keep that in mind!

    Allan
  • max4evermax4ever Posts: 45Questions: 0Answers: 0
    i switched to sessionStorage and put sessionStorage.clear() on the login page :)
This discussion has been closed.