cache.js 463 B

12345678910111213141516171819202122232425
  1. class SessionCache {
  2. setCache(key, value) {
  3. window.sessionStorage.setItem(key, JSON.stringify(value))
  4. }
  5. getCache(key) {
  6. // obj => string => obj
  7. const value = window.sessionStorage.getItem(key)
  8. if (value) {
  9. return JSON.parse(value)
  10. } else {
  11. return false
  12. }
  13. }
  14. deleteCache(key) {
  15. window.sessionStorage.removeItem(key)
  16. }
  17. clearCache() {
  18. window.sessionStorage.clear()
  19. }
  20. }
  21. export default new SessionCache()