20 lines
322 B
JavaScript
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
|
|
}
|