Skip to content

Commit ec7105a

Browse files
committedJul 18, 2024·
fix: unwatch storage on nitro close
1 parent 9c86298 commit ec7105a

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed
 

‎src/runtime/server/plugins/refresh-cache.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@ import type { WatchEvent } from 'unstorage';
44
// @ts-expect-error
55
import { useStorage } from '#imports'
66

7-
export default defineNitroPlugin(() => {
7+
export default defineNitroPlugin(async (nitro) => {
88
const storage = useStorage()
99

10-
storage.watch(async (event: WatchEvent, key: string) => {
10+
const unwatch = await storage.watch(async (event: WatchEvent, key: string) => {
1111
if (key.startsWith('content:source')) {
1212
cleanCachedContents();
1313
}
1414
});
15+
nitro.hooks.hook('close', async () => {
16+
typeof unwatch === 'function' && await unwatch()
17+
})
1518
})

0 commit comments

Comments
 (0)
Please sign in to comment.