UNPKG

spur-common

Version:

A Node.JS library of common modules used as a base to most Node.JS applications.

24 lines (16 loc) 457 B
module.exports = (Promise)-> new class FixtureCache constructor:()-> @cache = {} set:(key, value)=> @cache[key] = value get:(key)=> @cache[key] getOrPromise:(key, fn)=> cacheHit = @cache[key] if cacheHit return Promise.resolve(cacheHit) else return fn().then (result)=> @setAsync(key, result) return result setAsync:(key, value)-> setTimeout => @set(key, value)