mirror of
https://github.com/directus/directus.git
synced 2026-01-13 19:28:08 -05:00
* Setup shared redis abstraction * Install directus/memory * Add mini useEnv util for test mocking purposes * Export missing class from directus/memory * Update readme to include kv * Uninstall memory * Setup telemetry lib * Reduce concurrency * Finalize reporting * Add tests for send-report * Add tests for init * Add tests for tracker * Add tests for get-item-count * Add test for wait time * Add test for get-user-count * Add test for get-user-item-count * Fix type issue * Throw error on non-ok fetch * Init telemetry on server startup * Tweak submission logic * Fix tests, submit version * Update config-options reference * Cool kids don't use + in large numbers * Add changesets * Update docs/self-hosted/config-options.md Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch> * Use vi stubGlobal * Update api/src/env.ts Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch> * Unstub as well * Mock telemetry start in app test * Update api/src/telemetry/types/report.ts Co-authored-by: Azri Kahar <42867097+azrikahar@users.noreply.github.com> * Fix default value in env * Use toBoolean for env var casting * Don't rely on knex as Apparently it doesn't work reliably with count() * Update api/src/telemetry/lib/init-telemetry.ts Co-authored-by: Azri Kahar <42867097+azrikahar@users.noreply.github.com> * Use getDatabaseClient for consistent clients * Rename ingress->url * Send my apologies to the formatting bot * Fix version --------- Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch> Co-authored-by: Azri Kahar <42867097+azrikahar@users.noreply.github.com>
1.3 KiB
1.3 KiB
@directus/memory
Directus has various different needs for ephemeral storage that's synced between multiple processes for the same Directus 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 '@directus/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 '@directus/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 '@directus/memory';
const bus = createBus({
type: 'redis',
redis: new Redis(),
namespace: 'directus',
});
Limiter
The limiter class is a basic shared rate limiter.
Basic Usage
import { createLimiter } from '@directus/memory';
const limiter = createLimiter({
type: 'memory',
points: 10,
duration: 5,
});