https://github.com/localforage/localforage-memorystoragedriver
A volatile, in memory storage driver for localForage.
https://github.com/localforage/localforage-memorystoragedriver
Last synced: 7 months ago
JSON representation
A volatile, in memory storage driver for localForage.
- Host: GitHub
- URL: https://github.com/localforage/localforage-memorystoragedriver
- Owner: localForage
- License: other
- Created: 2016-05-06T05:18:30.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2016-08-31T12:23:31.000Z (almost 10 years ago)
- Last Synced: 2024-12-13T09:37:56.052Z (over 1 year ago)
- Language: JavaScript
- Size: 14.6 KB
- Stars: 17
- Watchers: 4
- Forks: 5
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
localforage-memoryStorageDriver
=================================
[](https://www.npmjs.com/package/localforage-memoryStorageDriver)
A **volatile**, in memory storage driver for [localForage](https://github.com/mozilla/localForage).
**The stored data are lost after a page reload.**
Originally designed for unit-testing (especially SPAs) and as a fallback for environmets without any storage APIs.
This driver serializes the stored items, so that
* it works consistently compared to the "native" localForage driver
* modifications of retrieved (complex) objects do not affect the stored items.
## Requirements
* [localForage](https://github.com/mozilla/localForage) v1.4.0+
## Installation
`npm i localforage-memoryStorageDriver`
## Example
[jsfiddle](https://jsfiddle.net/dp2dzyL9/)
```js
localforage.defineDriver(memoryStorageDriver).then(function() {
return localforage.setDriver(memoryStorageDriver._driver);
}).then(function() {
console.log('Active driver: ' + localforage.driver());
return localforage.setItem('test1', 'value1');
}).then(function() {
console.log('setItem(\'test1\', \'value1\')');
return localforage.getItem('test1');
}).then(function(value) {
console.log('getItem(\'test1\') => ' + value);
return localforage.clear();
})
```