1.0.0 • Published 3 years ago

local-storage-with-expiry v1.0.0

Weekly downloads
4
License
MIT
Repository
github
Last release
3 years ago

local-storage-with-expiry

A browser's Local storage that can expire like a Cookie.

Use case

A cookie can be made to expire after a specific duration. However, the combined size of all cookie can not exceed 4096 Bytes per domain. To store large size data, we have to rely on other browser storage systems like localstorage. The issue is that we can not set an expiry time for localstorage data. The "local-storage-with-expiry" comes with a feature to expire data stored in the localstorage. The data would expire the next time it tries to get it past expiry time.

Usage

var app_store = localStore("key_name");

// Setting expiry time to 1 hour
app_store.setExpiryTime(60*60*1000);

app_store.set({
  test : 'test123'
});

var value = app_store.get();


// Another store
var app_store_2 = localStore("key_name_2");

// Setting expiry time to 15 min
app_store_2.setExpiryTime(15*60*1000);

app_store_2.set({
  test : 'another-test'
});

var value_2 = app_store_2.get();