# i18next-localstorage-cache

> caching layer for i18next using browsers localStorage

Latest version **1.1.1** (published 2017-05-09) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install i18next-localstorage-cache
pnpm add i18next-localstorage-cache
yarn add i18next-localstorage-cache
bun add i18next-localstorage-cache
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2017-05-09 |
| First published | 2015-10-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Jan Mühlemann |
| Maintainers | adrai, jamuhl |
| Keywords | i18next, i18next-cache |

## Links

- npm: https://www.npmjs.com/package/i18next-localstorage-cache
- Homepage: https://github.com/i18next/i18next-localStorage-cache
- Issues: https://github.com/i18next/i18next-localStorage-cache/issues
- npm.io page: https://npm.io/package/i18next-localstorage-cache

## Alternatives

- [memory-cache](https://npm.io/package/memory-cache.md) — 795.0K weekly downloads
- [@httptoolkit/proxy-agent](https://npm.io/package/@httptoolkit/proxy-agent.md) — 11.2K weekly downloads
- [express-cache-controller](https://npm.io/package/express-cache-controller.md) — 5.3K weekly downloads
- [http-cache-middleware](https://npm.io/package/http-cache-middleware.md) — 4.5K weekly downloads
- [cache2](https://npm.io/package/cache2.md) — 1.5K weekly downloads

## Recent versions

- 1.1.1 (latest) — 2017-05-09
- 1.1.0 — 2017-02-25
- 1.0.0 — 2017-02-24
- 0.3.0 — 2016-04-07
- 0.2.2 — 2016-03-10
- 0.2.1 — 2016-03-09
- 0.2.0 — 2016-03-09
- 0.1.0 — 2016-03-04
- 0.0.4 — 2015-12-16
- 0.0.3 — 2015-10-29
- 0.0.2 — 2015-10-29
- 0.0.1 — 2015-10-28

## README

# Introduction

This is a i18next cache layer to be used in the browser. It will load and cache resources from localStorage.

# Getting started

Source can be loaded via [npm](https://www.npmjs.com/package/i18next-localstorage-cache), bower or [downloaded](https://github.com/i18next/i18next-localStorage-cache/blob/master/i18nextLocalStorageCache.min.js) from this repo.

- If you don't use a module loader it will be added to window.i18nextLocalStorageCache

```
# npm package
$ npm install i18next-localstorage-cache

# bower
$ bower install i18next-localstorage-cache
```

Wiring up:

```js
import i18next from 'i18next';
import Cache from 'i18next-localstorage-cache';

i18next
  .use(Cache)
  .init(i18nextOptions);
```

As with all modules you can either pass the constructor function (class) to the i18next.use or a concrete instance.

## Cache Options

**hint:** the cache plugin is disabled by default. Enable it by setting `enabled: true` in init options for production usage.

```js
{
  // turn on or off
  enabled: false,

  // prefix for stored languages
  prefix: 'i18next_res_',

  // expiration
  expirationTime: 7*24*60*60*1000,

  // language versions
  versions: {}
};
```

- Contrary to cookies behavior, the cache will respect updates to `expirationTime`. If you set 7 days and later update to 10 days, the cache will persist for 10 days

- Passing in a `versions` object (ex.: `versions: { en: 'v1.2', fr: 'v1.1' }`) will give you control over the cache based on translations version. This setting works along `expirationTime`, so a cached translation will still expire even though the version did not change. You can still set `expirationTime` far into the future to avoid this


Options can be passed in:

**preferred** - by setting options.cache in i18next.init:

```js
import i18next from 'i18next';
import Cache from 'i18next-localstorage-cache';

i18next
  .use(Cache)
  .init({
    cache: options
  });
```

on construction:

```js
  import Cache from 'i18next-localstorage-cache';
  const cache = new Cache(null, options);
```

via calling init:

```js
  import Cache from 'i18next-localstorage-cache';
  const cache = new Cache();
  cache.init(options);
```

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