fix: sync cachable

This commit is contained in:
Carl-Gerhard Lindesvärd
2025-11-10 11:42:14 +01:00
parent bb0e413b06
commit d8661acd66
4 changed files with 163 additions and 74 deletions

View File

@@ -1,4 +1,4 @@
import { cacheable } from '@openpanel/redis';
import { cacheable, cacheableLru } from '@openpanel/redis';
import type { Client, Prisma } from '../prisma-client';
import { db } from '../prisma-client';
@@ -34,8 +34,7 @@ export async function getClientById(
});
}
export const getClientByIdCached = cacheable(
getClientById,
60 * 60 * 24,
'both',
);
export const getClientByIdCached = cacheableLru(getClientById, {
maxSize: 1000,
ttl: 60 * 5,
});

View File

@@ -1,6 +1,6 @@
import { generateSalt } from '@openpanel/common/server';
import { cacheable } from '@openpanel/redis';
import { cacheableLru } from '@openpanel/redis';
import { db } from '../prisma-client';
export async function getCurrentSalt() {
@@ -17,7 +17,7 @@ export async function getCurrentSalt() {
return salt.salt;
}
export const getSalts = cacheable(
export const getSalts = cacheableLru(
'op:salt',
async () => {
const [curr, prev] = await db.salt.findMany({
@@ -42,8 +42,10 @@ export const getSalts = cacheable(
return salts;
},
60 * 10,
'both',
{
maxSize: 2,
ttl: 60 * 5,
},
);
export async function createInitialSalts() {