component-demo/cache.js
Joshua Bemenderfer 05c575bb26 Initial commit.
2020-09-22 20:42:46 -04:00

20 lines
322 B
JavaScript

import crypto from 'crypto'
export const cache = {}
export function hash(key) {
const hash = crypto.createHash('sha256')
.update(JSON.stringify(key))
.digest('hex')
return hash
}
export function toCache(hash, data) {
cache[hash] = data
}
export function fromCache(hash) {
return cache[hash] || null
}