MCPcopy Create free account
hub / github.com/dailydotdev/apps / createNoPostCache

Function createNoPostCache

packages/extension/src/background/noPostCache.ts:6–32  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

4export const NO_POST_CACHE_MAX_SIZE = 500;
5
6export const createNoPostCache = () => {
7 const cache = new Map<string, number>();
8
9 const has = (url: string, now = Date.now()): boolean => {
10 const expiresAt = cache.get(url);
11 if (!expiresAt) {
12 return false;
13 }
14
15 if (expiresAt > now) {
16 return true;
17 }
18
19 cache.delete(url);
20 return false;
21 };
22
23 const add = (url: string, now = Date.now()): void => {
24 cache.delete(url);
25 cache.set(url, now + NO_POST_CACHE_TTL);
26 if (cache.size > NO_POST_CACHE_MAX_SIZE) {
27 cache.delete(cache.keys().next().value as string);
28 }
29 };
30
31 return { has, add };
32};
33
34export const noPostCache = createNoPostCache();

Callers 2

noPostCache.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected