Skip to content

Commit

Permalink
feat(client-db): allow possibility to ignore some sources from client…
Browse files Browse the repository at this point in the history
… storage
  • Loading branch information
farnabaz committed Feb 21, 2023
1 parent e82af75 commit 9f15fd0
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/runtime/composables/client-db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,21 @@ export const getPreview = () => {

export function createDB (storage: Storage) {
async function getItems () {
const keys = new Set(await storage.getKeys('cache:'))
const keys = new Set<string>(await storage.getKeys('cache:'))

// Merge preview items
const previewToken = getPreview()
if (previewToken) {
// Ignore cache content if preview requires it
const previewMeta: any = await storage.getItem(`${previewToken}$`).then(data => data || {})
if (previewMeta.ignoreBuiltContents) {
keys.clear()
if (previewMeta.ignoreSources) {
const sources = previewMeta.ignoreSources.split(',').map(s => `cache:${s.trim()}:`)
// Remove all keys that starts with ignored sources
for (const key of keys) {
if (sources.some(s => key.startsWith(s))) {
keys.delete(key)
}
}
}

const previewKeys = await storage.getKeys(`${previewToken}:`)
Expand Down

0 comments on commit 9f15fd0

Please sign in to comment.