useCache.ts 535 B

123456789101112131415161718192021222324252627
  1. /**
  2. * 配置浏览器本地存储的方式,可直接存储对象数组。
  3. */
  4. import WebStorageCache from 'web-storage-cache'
  5. type CacheType = 'localStorage' | 'sessionStorage'
  6. export const CACHE_KEY = {
  7. IS_DARK: 'isDark',
  8. USER: 'user',
  9. LANG: 'lang',
  10. THEME: 'theme',
  11. LAYOUT: 'layout',
  12. ROLE_ROUTERS: 'roleRouters',
  13. DICT_CACHE: 'dictCache'
  14. }
  15. export const useCache = (type: CacheType = 'localStorage') => {
  16. const wsCache: WebStorageCache = new WebStorageCache({
  17. storage: type
  18. })
  19. return {
  20. wsCache
  21. }
  22. }