
The MemoryStorage is a SyncStorage that uses a Map as its storage, which means that it will only be available in the current session.
The set method sets an item in the storage. Optionally, you can specify the keys of the item that you want to set. If you don’t specify any key, the whole item will be set.
import { MemoryStorage } from '@aracna/core';
MemoryStorage.set('item', { name: 'John', surname: 'Doe' });
// will log { name: "John", surname: "Doe" }
console.log(MemoryStorage.get('item'));The get method retrieves an item from the storage. Optionally, you can specify the keys of the item that you want to get. If you don’t specify any key, the whole item will be retrieved.
import { MemoryStorage } from '@aracna/core';
MemoryStorage.set('item', { name: 'John', surname: 'Doe' });
// will log { name: "John", surname: "Doe" }
console.log(MemoryStorage.get('item'));The remove method removes an item from the storage. Optionally, you can specify the keys of the item that you want to remove. If you don’t specify any key, the whole item will be removed.
import { MemoryStorage } from '@aracna/core';
MemoryStorage.set('item', { name: 'John', surname: 'Doe' });
MemoryStorage.remove('item');
// will log false
console.log(MemoryStorage.has('item'));The clear method clears the storage, removing all the items.
import { MemoryStorage } from '@aracna/core';
MemoryStorage.set('item1', { name: 'John', surname: 'Doe' });
MemoryStorage.set('item2', { name: 'Paul', surname: 'Smith' });
MemoryStorage.clear();
// will log false, false
console.log(MemoryStorage.has('item1'), MemoryStorage.has('item2'));The copy method copies an item from the storage to a target object. Optionally, you can specify the keys of the item that you want to copy. If you don’t specify any key, the whole item will be copied.
import { MemoryStorage } from '@aracna/core';
const target = {};
MemoryStorage.set('item', { name: 'John', surname: 'Doe' });
MemoryStorage.copy('item', target);
// will log { name: "John", surname: "Doe" }
console.log(target);The has method checks if an item exists in the storage. Optionally, you can specify the keys of the item that you want to check. If you don’t specify any key, the whole item will be checked.
import { MemoryStorage } from '@aracna/core';
MemoryStorage.set('item', { name: 'John', surname: 'Doe' });
// will log true
console.log(MemoryStorage.has('item'));