1.0.1 • Published 5 years ago

js-frontend-caching v1.0.1

Weekly downloads
1
License
ISC
Repository
github
Last release
5 years ago

JS Frontend Caching

:mega: Now Include Local Storage & Cookie!

A simple, and lightweight helper function that can help you to cache your data in your browser!

Installation

Install the helper using npm:

npm install js-frontend-caching --save

Example

    const js_caching = require('js-frontend-caching');

    function tell_someone(){
        console.log("I saved your name!")
    }

    var name = "Kevin";



    js_caching.init('localstorage'); //Save the cache using localstorage

    //Save Kevin with name_person as a key. After that, do tell_someone()
    js_caching.save('name_person', name, tell_someone, 5);

Usage

Call the lib to your app:

    const js_caching = require('js-frontend-caching');

Then initialize the js-frontend-caching

    //This will initialize Cookie to be the Driver
    js_caching.init('cookie')

If you want to save the data, do the following code:

    function callback_function() {
        console.log("I saved your age");
    }

    var age = 19;

    //This will put var age to the age_people key, with 5 min timeout
    js_caching.save('age_people', age, callback_function, 5);

If you want to retreive the data, do the following code:

    function errorHandling() {
        return 19
    }

    //This will retrieve age_people and will put the value into var age
    //If age_people is not present at your cache, errorHandling will executed and will use the return value
    var age = js_caching.get('age_people', errorHandling);
1.0.1

5 years ago

1.0.0

5 years ago