andresusandi-storage
Version:
storage utilities for distributed systems
31 lines (25 loc) • 590 B
JavaScript
class InMemoryStorage {
constructor() {
this.store = {};
}
init() {
}
save(key, value) {
this.store[key] = value;
}
get(key) {
return (this.store[key]);
}
delete(key) {
delete this.store[key];
}
getAllItems() {
const keys = Object.keys(this.store);
const values = Object.values(this.store);
const items = [];
for (var i = 0; i < keys.length; i++)
items.push({ key: keys[i], value: values[i] });
return (items);
}
}
module.exports = InMemoryStorage;