axios-cache-adapter
Version:
Caching adapter for axios
38 lines (27 loc) • 573 B
JavaScript
import { mapObject } from './utilities'
class MemoryStore {
constructor () {
this.store = {}
}
async getItem (key) {
const item = this.store[key] || null
return JSON.parse(item)
}
async setItem (key, value) {
this.store[key] = JSON.stringify(value)
return value
}
async removeItem (key) {
delete this.store[key]
}
async clear () {
this.store = {}
}
async length () {
return Object.keys(this.store).length
}
iterate (fn) {
return Promise.all(mapObject(this.store, fn))
}
}
export default MemoryStore