Last active
November 5, 2015 16:32
-
-
Save clalimarmo/8911d3ecdee41e378e38 to your computer and use it in GitHub Desktop.
Collection+JSON in-memory caching
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
const Cache = function(deps) { | |
const self = {}; | |
const requested = {}; | |
self.fetch = function(href) { | |
requested[href] = requested[href] || new Promise((resolve, reject) => { | |
const collection = deps.Collection(); | |
collection.fetch(href).done(() => { | |
resolve(collection); | |
}); | |
}); | |
return requested[href]; | |
}; | |
return self; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment