enhance(backend): improve cache

This commit is contained in:
syuilo 2023-04-04 17:32:09 +09:00
parent 7f3afac0a2
commit ecaf152b4a
21 changed files with 184 additions and 89 deletions

View file

@ -4,7 +4,7 @@ import type { NotesRepository, UsersRepository } from '@/models/index.js';
import type { Config } from '@/config.js';
import { MetaService } from '@/core/MetaService.js';
import { MAX_NOTE_TEXT_LENGTH } from '@/const.js';
import { MemoryKVCache } from '@/misc/cache.js';
import { MemoryCache } from '@/misc/cache.js';
import { UserEntityService } from '@/core/entities/UserEntityService.js';
import { bindThis } from '@/decorators.js';
import NotesChart from '@/core/chart/charts/notes.js';
@ -118,17 +118,17 @@ export class NodeinfoServerService {
};
};
const cache = new MemoryKVCache<Awaited<ReturnType<typeof nodeinfo2>>>(1000 * 60 * 10);
const cache = new MemoryCache<Awaited<ReturnType<typeof nodeinfo2>>>(1000 * 60 * 10);
fastify.get(nodeinfo2_1path, async (request, reply) => {
const base = await cache.fetch(null, () => nodeinfo2());
const base = await cache.fetch(() => nodeinfo2());
reply.header('Cache-Control', 'public, max-age=600');
return { version: '2.1', ...base };
});
fastify.get(nodeinfo2_0path, async (request, reply) => {
const base = await cache.fetch(null, () => nodeinfo2());
const base = await cache.fetch(() => nodeinfo2());
delete (base as any).software.repository;