Skip to content

Instantly share code, notes, and snippets.

@craigspaeth
Last active August 29, 2015 13:57
Show Gist options
  • Save craigspaeth/9419092 to your computer and use it in GitHub Desktop.
Save craigspaeth/9419092 to your computer and use it in GitHub Desktop.
# API examples
cache artist, 'fetch', success: ->
#...
cache artworks, 'fetchUntilEnd', success: (artworks) ->
res.render artworks: artworks
cache fair, 'fetchExhibitors', success: ->
# ...
# Implementation
cache = (model, method, options) ->
key = method + ':' + model.url()
if res = client.get key
return options.success(model, res)
else
model['method'] _.extend options,
success: ->
options.success arguments...
client.set key, model.toJSON()
client.expire key, model.toJSON()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment