Skip to content

Instantly share code, notes, and snippets.

@clalimarmo
Last active November 5, 2015 16:32
Show Gist options
  • Save clalimarmo/8911d3ecdee41e378e38 to your computer and use it in GitHub Desktop.
Save clalimarmo/8911d3ecdee41e378e38 to your computer and use it in GitHub Desktop.
Collection+JSON in-memory caching
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