caffeine-mc
Version:
Select, configure and extend your to-JavaScript compiler, with arbitrary code, on a per file bases from within the file.
35 lines (26 loc) • 855 B
text/coffeescript
{
defineModule, peek, Promise, dashCase, upperCamelCase,
ErrorWithInfo, log, merge, present, find, each, w
mergeInto
currentSecond
} = require 'art-standard-lib'
workingCache = null
cacheExpiresIn = 1
workingCacheLastResetAt = currentSecond() - cacheExpiresIn * 10
module.exports =
checkWorkingCacheExpiration: ->
if currentSecond() - workingCacheLastResetAt > cacheExpiresIn
resetWorkingCache()
resetWorkingCache: resetWorkingCache = ->
workingCache = {}
cacheRead: cacheRead = (key, p) -> workingCache[key]?[p]
cacheWrite: cacheWrite = (key, p, v) -> (workingCache[key]?={})[p] = v
cacheable: (key, f) ->
(p) ->
if (v = cacheRead key, p)?
v
else
cacheWrite key, p, f p
resetWorkingCache()