Skip to content

This package aims to implement a storage that offers a way to specify an expiring date of the items stored.

Notifications You must be signed in to change notification settings

DevM3Team/expiring-local-storage

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Expiring Local Storage

This package aims to implement a storage that offers a way to specify an expiring date of the items stored.

Set Item

In order to save an object inside the storage you have to use the method setItem of the ExpiringStorage class. The function has two mandatory parameters and one optional parameter. The mandatory parameters are the key that identifies the item and the item itself, the optional parameter is the time (in seconds) at the end of which the item will expire. Only JSON representable data is accepted

import {ExpiringStorage} from "./expiring-storage";

let item = {name: "string"};
ExpiringStorage.setItem('key', item, 60); // This item will expire in 60 seconds

Get Item

The method to retrieve an object that's stored inside the storage works like the localStorage one, with the method getItem of the ExpiringStorage class. The method requires the key of the item. If the item is expired the method will return null.

import {ExpiringStorage} from "./expiring-storage";

let item = ExpiringStorage.getItem('key'); //The item will be returned if it isn't expired otherwise it'll be null

About

This package aims to implement a storage that offers a way to specify an expiring date of the items stored.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published