Skip to content

Commit 42ba29d

Browse files
committed
refactor: move lru-cache
1 parent 296ffab commit 42ba29d

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { deleteApp, type FirebaseApp } from 'firebase/app'
2+
import { LRUCache } from 'lru-cache'
3+
4+
// TODO: allow customizing
5+
// TODO: find sensible defaults. Should they change depending on the platform?
6+
7+
// copied from https://github.com/FirebaseExtended/firebase-framework-tools/blob/e69f5bdd44695274ad88dbb4e21aac778ba60cc8/src/constants.ts
8+
export const LRU_MAX_INSTANCES = 100
9+
export const LRU_TTL = 1_000 * 60 * 5
10+
export const appCache = new LRUCache<string, FirebaseApp>({
11+
max: LRU_MAX_INSTANCES,
12+
ttl: LRU_TTL,
13+
allowStale: true,
14+
updateAgeOnGet: true,
15+
dispose: (value) => {
16+
deleteApp(value)
17+
},
18+
})

packages/nuxt/src/runtime/app/plugin.server.ts

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,11 @@
1-
import { deleteApp, type FirebaseApp, initializeApp } from 'firebase/app'
1+
import { type FirebaseApp, initializeApp } from 'firebase/app'
22
import { type User } from 'firebase/auth'
33
import { DecodedIdToken } from 'firebase-admin/auth'
4-
import { LRUCache } from 'lru-cache'
54
import { logger } from '../logging'
65
import { DECODED_ID_TOKEN_SYMBOL } from '../constants'
6+
import { appCache } from './lru-cache'
77
import { defineNuxtPlugin, useAppConfig } from '#app'
88

9-
// TODO: allow customizing
10-
// TODO: find sensible defaults. Should they change depending on the platform?
11-
// copied from https://github.com/FirebaseExtended/firebase-framework-tools/blob/e69f5bdd44695274ad88dbb4e21aac778ba60cc8/src/constants.ts
12-
export const LRU_MAX_INSTANCES = 100
13-
export const LRU_TTL = 1_000 * 60 * 5
14-
const appCache = new LRUCache<string, FirebaseApp>({
15-
max: LRU_MAX_INSTANCES,
16-
ttl: LRU_TTL,
17-
allowStale: true,
18-
updateAgeOnGet: true,
19-
dispose: (value) => {
20-
deleteApp(value)
21-
},
22-
})
23-
249
/**
2510
* Initializes the app and provides it to others.
2611
*/

0 commit comments

Comments
 (0)