Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(client-db): allow possibility to ignore some sources from client storage #1917

Merged
merged 1 commit into from
Feb 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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