Created
March 2, 2016 01:23
-
-
Save samelliott89/f42c7a578c0103856fb9 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
// 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