Skip to content

Commit 290710a

Browse files
authored
fix: add bust-cache on dev startup (#2055)
1 parent 83bd4c4 commit 290710a

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

src/bustCache.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Redis } from 'ioredis';
2+
3+
import { REDIS_CONNECTION } from './config/redis';
4+
5+
export async function bustFileCache() {
6+
const redis = new Redis(REDIS_CONNECTION);
7+
8+
console.debug('DEV: Busting Redis cache for file urls');
9+
const cache_keys = await redis.keys('file_service_url_caching*');
10+
console.debug(`DEV: Removing ${cache_keys.length} keys`);
11+
cache_keys.forEach((key) => {
12+
redis.expire(key, 0);
13+
});
14+
console.debug('DEV: Done busting cache');
15+
}

src/fastify.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { TypeBoxTypeProvider } from '@fastify/type-provider-typebox';
33
import { fastify } from 'fastify';
44

55
import registerAppPlugins from './app';
6+
import { bustFileCache } from './bustCache';
67
import { DEV, NODE_ENV, PROD } from './config/env';
78
import { client } from './drizzle/db';
89
import ajvFormats from './schemas/ajvFormats';
@@ -66,6 +67,7 @@ const start = async () => {
6667
// greet the world
6768
// eslint-disable-next-line no-console
6869
console.log(`${GREETING}`);
70+
await bustFileCache();
6971
}
7072
} catch (err) {
7173
instance.log.error(err);

0 commit comments

Comments
 (0)