Skip to content

Instantly share code, notes, and snippets.

@samelliott89
Created March 2, 2016 01:23
Show Gist options
  • Save samelliott89/f42c7a578c0103856fb9 to your computer and use it in GitHub Desktop.
Save samelliott89/f42c7a578c0103856fb9 to your computer and use it in GitHub Desktop.
// if there is a cache, fetch from it
if (CacheFactory.get('plansCache')) {
var plansCache = CacheFactory.get('plansCache');
vm.plans = plansCache.get("/plans");
console.log("fetching from cache");
console.log(vm.plans);
setupPlans(vm.plans);
};
// if there is no cache, create one
if (!CacheFactory.get('plansCache')) {
// create the plans cache object
// and set some parameters
CacheFactory.createCache('plansCache', {
deleteOnExpire: 'aggressive',
recycleFreq: 21600000 /* Refresh every 6 hours */
});
console.log("creating cache object");
console.log(vm.plans);
};
if (typeof vm.plans === 'undefined') {
// queries endpoint for list of plans
PlanService.query({
"ordering": "price"
}, function(response) {
console.log("querying plans");
var plansCache = CacheFactory.get('plansCache');
vm.plans = response.results;
plansCache.put("/plans", vm.plans);
console.log("pushing to cache");
console.log(vm.plans);
setupPlans(vm.plans);
})
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment