Skip to content

Instantly share code, notes, and snippets.

@makyo
Created May 29, 2014 17:36
Show Gist options
  • Save makyo/9c87f5afd2c346620868 to your computer and use it in GitHub Desktop.
Save makyo/9c87f5afd2c346620868 to your computer and use it in GitHub Desktop.
diff --git a/app/store/charmworld.js b/app/store/charmworld.js
index c164653..7c8d783 100644
--- a/app/store/charmworld.js
+++ b/app/store/charmworld.js
@@ -59,15 +59,21 @@ YUI.add('juju-charm-store', function(Y) {
apiEndpoint = apiEndpoint + '?' + Y.QueryString.stringify(args);
}
+ var cachedResults = this.get('cachedResults')[apiEndpoint];
+ if (cachedResults) {
+ callbacks.success(cachedResults);
+ }
+
return this.sendRequest({
request: apiEndpoint,
callback: {
- 'success': function(io_request) {
+ 'success': Y.bind(function(io_request) {
var res = Y.JSON.parse(
io_request.response.results[0].responseText
);
+ this.get('cachedResults')[io_request.request] = res;
callbacks.success(res);
- },
+ }, this),
'failure': function(io_request) {
var respText = io_request.response.results[0].responseText,
@@ -114,6 +120,16 @@ YUI.add('juju-charm-store', function(Y) {
}, {
ATTRS: {
+ /**
+ * Cached results from non-charm requests.
+ *
+ * @attribute cachedResults
+ * @default empty
+ * @type {Object}
+ */
+ cachedResults: {
+ value: {}
+ },
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment