Skip to content
This repository was archived by the owner on Jan 26, 2024. It is now read-only.

Commit 4b85bb5

Browse files
committed
cache storage inits with local storage by default
1 parent 9e80426 commit 4b85bb5

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

core/modules/initCacheStorage.ts

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
11
import * as localForage from 'localforage'
22
import UniversalStorage from '@vue-storefront/core/store/lib/storage'
33
import { currentStoreView } from '@vue-storefront/store/lib/multistore'
4-
// use it to initialize cache storage in modules
5-
export function initCacheStorage(key) {
4+
import rootStore from '@vue-storefront/store'
5+
6+
7+
export function initCacheStorage(key, localised = true) {
68
const storeView = currentStoreView()
79
const dbNamePrefix = storeView.storeCode ? storeView.storeCode + '-' : ''
10+
const config = rootStore.state.config
11+
const cacheDriver = config.localForage && config.localForage.defaultDrivers['orders'] || 'LOCALSTORAGE'
812

9-
const cacheStorage = new UniversalStorage(localForage.createInstance({
10-
name: dbNamePrefix + 'shop',
11-
storeName: key
12-
}))
13-
14-
return cacheStorage
13+
if (localised) {
14+
const cacheStorage = new UniversalStorage(localForage.createInstance({
15+
name: dbNamePrefix + 'shop',
16+
storeName: key,
17+
driver: localForage[cacheDriver]
18+
}))
19+
return cacheStorage
20+
} else {
21+
const cacheStorage = new UniversalStorage(localForage.createInstance({
22+
name: 'shop',
23+
storeName: key,
24+
driver: localForage[cacheDriver]
25+
}))
26+
return cacheStorage
27+
}
1528
}

0 commit comments

Comments
 (0)