@clairview/memory
TypeScript icon, indicating that this package has built-in type declarations

2.0.3 • Public • Published

@clairview/memory

Clairview has various different needs for ephemeral storage that's synced between multiple processes for the same Clairview Projects. To streamline that setup, this package exports three classes that are used for everything related to ephemeral storage:

Kv

The Kv class is a simple key-value store

Basic Usage

import { createKv } from '@clairview/memory';

const cache = createKv({
	type: 'memory',
});

await cache.set('my-key', 'my-value');

Cache

The cache class is a Kv class extended with an LRU store

Basic Usage

import { createCache } from '@clairview/memory';

const cache = createCache({
	type: 'memory',
	maxKeys: 500,
});

await cache.set('my-key', 'my-value');

Bus

The bus class is a pub-sub abstraction. The memory type bus just handles local handlers, which adds no benefit next to having a shared API for using pubsub.

Basic Usage

import { Redis } from 'ioredis';
import { createBus } from '@clairview/memory';

const bus = createBus({
	type: 'redis',
	redis: new Redis(),
	namespace: 'clairview',
});

Limiter

The limiter class is a basic shared rate limiter.

Basic Usage

import { createLimiter } from '@clairview/memory';

const limiter = createLimiter({
	type: 'memory',
	points: 10,
	duration: 5,
});

Readme

Keywords

none

Package Sidebar

Install

npm i @clairview/memory

Homepage

clairview.io

Weekly Downloads

2

Version

2.0.3

License

MIT

Unpacked Size

31.3 kB

Total Files

5

Last publish

Collaborators

  • clairview