JavaScript Memory Cache

JS
S
JavaScript

Simple memory cache in JavaScript

1// Cache
2const cacheFactory = () => {
3  var store = {};
4  return {
5    has(key) { return (key in store); },
6    get(key) { return store[key]; },
7    set(key, value) { store[key] = value; }
8  };
9}
10const cache = cacheFactory();
11cache.set('hyundai', 'i30n');
12console.log(cache.has('hyundai'));
13console.log(cache.get('hyundai'));

Created on 3/12/2019