# js-frontend-caching

> JS Helper for Front End Caching

Latest version **1.0.1** (published 2019-08-05) · ISC license · 0 weekly downloads

## Install

```sh
npm install js-frontend-caching
pnpm add js-frontend-caching
yarn add js-frontend-caching
bun add js-frontend-caching
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2019-08-05 |
| First published | 2019-07-30 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 4.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Taufan Raifaldy Maaruf |
| Maintainers | topankentang |
| Keywords | JS, Frontend, Caching |

## Links

- npm: https://www.npmjs.com/package/js-frontend-caching
- Repository: https://github.com/topankentang/js-frontend-caching
- Homepage: https://github.com/topankentang/js-frontend-caching#readme
- Issues: https://github.com/topankentang/js-frontend-caching/issues
- npm.io page: https://npm.io/package/js-frontend-caching

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.0.1 (latest) — 2019-08-05
- 1.0.0 — 2019-07-30

## README

# 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](https://www.npmjs.com/package/js-frontend-caching):

```bash
npm install js-frontend-caching --save
```

## Example

```js
    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:
```js
    const js_caching = require('js-frontend-caching');
```

Then initialize the js-frontend-caching
```js
    //This will initialize Cookie to be the Driver
    js_caching.init('cookie')
```

If you want to save the data, do the following code:
```js
    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:
```js
    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);

```

---
_Source: https://npm.io/package/js-frontend-caching · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
