Skip to content

Commit 8bd2b77

Browse files
committed
replace all memory stores with the lru memory store
1 parent 336a6f0 commit 8bd2b77

File tree

6 files changed

+12
-36
lines changed

6 files changed

+12
-36
lines changed

apps/webapp/app/services/authorizationRateLimitMiddleware.server.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createCache, DefaultStatefulContext, Namespace, Cache as UnkeyCache } from "@unkey/cache";
2-
import { MemoryStore } from "@unkey/cache/stores";
2+
import { createLRUMemoryStore } from "@internal/cache";
33
import { Ratelimit } from "@upstash/ratelimit";
44
import { Request as ExpressRequest, Response as ExpressResponse, NextFunction } from "express";
55
import { createHash } from "node:crypto";
@@ -157,10 +157,7 @@ export function authorizationRateLimitMiddleware({
157157
limiterConfigOverride,
158158
}: Options) {
159159
const ctx = new DefaultStatefulContext();
160-
const memory = new MemoryStore({
161-
persistentMap: new Map(),
162-
unstableEvictOnSet: { frequency: 0.001, maxItems: limiterCache?.maxItems ?? 1000 },
163-
});
160+
const memory = createLRUMemoryStore(limiterCache?.maxItems ?? 1000);
164161
const redisCacheStore = new RedisCacheStore({
165162
connection: {
166163
keyPrefix: `cache:${keyPrefix}:rate-limit-cache:`,

apps/webapp/app/services/betterstack/betterstack.server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { type ApiResult, wrapZodFetch } from "@trigger.dev/core/v3/zodfetch";
22
import { createCache, DefaultStatefulContext, Namespace } from "@unkey/cache";
3-
import { MemoryStore } from "@unkey/cache/stores";
3+
import { createLRUMemoryStore } from "@internal/cache";
44
import { z } from "zod";
55
import { env } from "~/env.server";
66

@@ -17,7 +17,7 @@ const IncidentSchema = z.object({
1717
export type Incident = z.infer<typeof IncidentSchema>;
1818

1919
const ctx = new DefaultStatefulContext();
20-
const memory = new MemoryStore({ persistentMap: new Map() });
20+
const memory = createLRUMemoryStore(100);
2121

2222
const cache = createCache({
2323
query: new Namespace<ApiResult<Incident>>(ctx, {

apps/webapp/app/services/platform.v3.server.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
type CurrentPlan,
1616
} from "@trigger.dev/platform";
1717
import { createCache, DefaultStatefulContext, Namespace } from "@unkey/cache";
18-
import { MemoryStore } from "@unkey/cache/stores";
18+
import { createLRUMemoryStore } from "@internal/cache";
1919
import { existsSync, readFileSync } from "node:fs";
2020
import { redirect } from "remix-typedjson";
2121
import { z } from "zod";
@@ -45,13 +45,7 @@ const client = singleton("billingClient", initializeClient);
4545

4646
function initializePlatformCache() {
4747
const ctx = new DefaultStatefulContext();
48-
const memory = new MemoryStore({
49-
persistentMap: new Map(),
50-
unstableEvictOnSet: {
51-
frequency: 0.01,
52-
maxItems: 1000,
53-
},
54-
});
48+
const memory = createLRUMemoryStore(1000);
5549
const redisCacheStore = new RedisCacheStore({
5650
connection: {
5751
keyPrefix: "tr:cache:platform:v3",

apps/webapp/app/services/realtimeClient.server.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { longPollingFetch } from "~/utils/longPollingFetch";
88
import { logger } from "./logger.server";
99
import { jumpHash } from "@trigger.dev/core/v3/serverOnly";
1010
import { Cache, createCache, DefaultStatefulContext, Namespace } from "@unkey/cache";
11-
import { MemoryStore } from "@unkey/cache/stores";
11+
import { createLRUMemoryStore } from "@internal/cache";
1212
import { RedisCacheStore } from "./unkey/redisCacheStore.server";
1313
import { env } from "~/env.server";
1414
import { API_VERSIONS, CURRENT_API_VERSION } from "~/api/versions";
@@ -84,10 +84,7 @@ export class RealtimeClient {
8484
this.#registerCommands();
8585

8686
const ctx = new DefaultStatefulContext();
87-
const memory = new MemoryStore({
88-
persistentMap: new Map(),
89-
unstableEvictOnSet: { frequency: 0.01, maxItems: 1000 },
90-
});
87+
const memory = createLRUMemoryStore(1000);
9188
const redisCacheStore = new RedisCacheStore({
9289
connection: {
9390
keyPrefix: "tr:cache:realtime",

apps/webapp/app/services/requestIdempotency.server.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Logger, LogLevel } from "@trigger.dev/core/logger";
22
import { createCache, DefaultStatefulContext, Namespace, Cache as UnkeyCache } from "@unkey/cache";
3-
import { MemoryStore } from "@unkey/cache/stores";
3+
import { createLRUMemoryStore } from "@internal/cache";
44
import { RedisCacheStore } from "./unkey/redisCacheStore.server";
55
import { RedisWithClusterOptions } from "~/redis.server";
66
import { validate as uuidValidate, version as uuidVersion } from "uuid";
@@ -33,13 +33,7 @@ export class RequestIdempotencyService<TTypes extends string> {
3333
: "request-idempotency:";
3434

3535
const ctx = new DefaultStatefulContext();
36-
const memory = new MemoryStore({
37-
persistentMap: new Map(),
38-
unstableEvictOnSet: {
39-
frequency: 0.001,
40-
maxItems: 1000,
41-
},
42-
});
36+
const memory = createLRUMemoryStore(1000);
4337
const redisCacheStore = new RedisCacheStore({
4438
name: "request-idempotency",
4539
connection: {

apps/webapp/app/v3/marqs/fairDequeuingStrategy.server.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createCache, DefaultStatefulContext, Namespace, Cache as UnkeyCache } from "@unkey/cache";
2-
import { MemoryStore } from "@unkey/cache/stores";
2+
import { createLRUMemoryStore } from "@internal/cache";
33
import { randomUUID } from "crypto";
44
import { Redis } from "ioredis";
55
import { EnvQueues, MarQSFairDequeueStrategy, MarQSKeyProducer } from "./types";
@@ -99,13 +99,7 @@ export class FairDequeuingStrategy implements MarQSFairDequeueStrategy {
9999

100100
constructor(private options: FairDequeuingStrategyOptions) {
101101
const ctx = new DefaultStatefulContext();
102-
const memory = new MemoryStore({
103-
persistentMap: new Map(),
104-
unstableEvictOnSet: {
105-
frequency: 0.01,
106-
maxItems: 500,
107-
},
108-
});
102+
const memory = createLRUMemoryStore(500);
109103

110104
this._cache = createCache({
111105
concurrencyLimit: new Namespace<number>(ctx, {

0 commit comments

Comments
 (0)