Last active
August 29, 2015 13:57
-
-
Save craigspaeth/9419092 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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