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
text/coffeescript
module.exports = (Promise)->
new class FixtureCache
constructor:()->
= {}
set:(key, value)=> [key] = value
get:(key)=> [key]
getOrPromise:(key, fn)=>
cacheHit = [key]
if cacheHit
return Promise.resolve(cacheHit)
else
return fn().then (result)=>
(key, result)
return result
setAsync:(key, value)-> setTimeout =>
(key, value)