https://github.com/axtk/memory-storage
An in-memory storage with a customizable capacity and with a localStorage-like API
https://github.com/axtk/memory-storage
in-memory localstorage-api storage
Last synced: 10 months ago
JSON representation
An in-memory storage with a customizable capacity and with a localStorage-like API
- Host: GitHub
- URL: https://github.com/axtk/memory-storage
- Owner: axtk
- Created: 2020-12-13T04:11:32.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-03-23T01:11:46.000Z (over 5 years ago)
- Last Synced: 2025-08-18T20:00:28.420Z (10 months ago)
- Topics: in-memory, localstorage-api, storage
- Language: JavaScript
- Homepage:
- Size: 9.77 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[](https://www.npmjs.com/package/@axtk/memory-storage)


*An in-memory storage with a customizable capacity and with a localStorage-like API*
## `class MemoryStorage`
```js
const MemoryStorage = require('@axtk/memory-storage');
const storage = new MemoryStorage(10);
storage.setItem('x', 1);
let x = storage.getItem('x');
```
#### `new MemoryStorage(capacity?)`
Creates an in-memory storage instance with the given `capacity`.
- **`capacity?: number`**
- A maximum number of entries to be stored. When the number of entries reaches this value adding a new entry to the storage will cause the first added entry to be removed from the storage to maintain the capacity.
- Default: `Infinity`.
The methods of the `MemoryStorage` class are in line with the [`Storage`](https://developer.mozilla.org/en-US/docs/Web/API/Storage) interface.