mirror of
https://github.com/directus/directus.git
synced 2026-01-13 14:27:59 -05:00
* Add analytics table * Setup memory package boilerplate * Bootstrap library * [WIP] setup serialize/deserialize for data * Finish compress/serialize utils * Add get/set for local * Add increments method * Add delete + comments * Add pub/sub methods * Remove erroneous files * Add has, setMax * Restructure to 3 subclasses * WIP add Redis cache * Add set-max * Add cacheMulti * Add tests for redis cache * Don't compress small values * Only decompress values that are compressed * Add test for arr-to-buf * Add tests for multi-stage cache * Add test for create * Finish redis based messenger bus * Add redis bus to createBus * Resolve lock file conflict * Align dev deps versions * Format files * Update packages/memory/package.json Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch> * It's okay, ESLint * Add local rate limiter * Add redis limiter * Add simple readme * Add changeset * 'key value' -> 'key-value' * Sort package.json * Remove leftovers * Move timer calls to corresponding test * Add KV asbraction based on previous "cache" * Update cache to use kv * Add more specific console logs * Only define setMax if not exists * Run formatter * Use parseJSON util * Fix typo in class docs * Install directus/utils * Default to Map if LRU config isn't set * Ignore errors thrown in handlers * Create process-id util * Use pubsub in multi-stage handler * WIP Update tests * Update package lock * Fix formatting errors * Fix timestamp in test * Uno mas * Fix mock order --------- Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch>
20 lines
511 B
TypeScript
20 lines
511 B
TypeScript
import { createHash } from 'node:crypto';
|
|
import { hostname } from 'node:os';
|
|
|
|
export const _cache: { id: string | undefined } = { id: undefined };
|
|
|
|
/**
|
|
* Return a unique hash for the current process on the current machine. Will be different after a
|
|
* restart
|
|
*/
|
|
export const processId = () => {
|
|
if (_cache.id) return _cache.id;
|
|
|
|
const parts = [hostname(), process.pid, new Date().getTime()];
|
|
const hash = createHash('md5').update(parts.join(''));
|
|
|
|
_cache.id = hash.digest('hex');
|
|
|
|
return _cache.id;
|
|
};
|