Skip to content

Commit

Permalink
feature/settings — Capacity to empty cache on demand (http + images).
Browse files Browse the repository at this point in the history
  • Loading branch information
jeandat committed Feb 13, 2016
1 parent 43f2cca commit 67a64ea
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
24 changes: 20 additions & 4 deletions app/settings/settings.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
.module('app')
.controller('SettingsController', SettingsController);

function SettingsController($log, $scope, $cordovaToast, defaultCacheName, CacheFactory, $ionicPopup, throwErr) {
function SettingsController($log, $scope, $cordovaToast, defaultCacheName, CacheFactory,
$ionicPopup, throwErr, ImgCache, $timeout) {

var vm = this;
vm.settings = {
enableCache: true
};
vm.clearing = false;
vm.clearCache = clearCache;

activate();
Expand All @@ -24,7 +26,7 @@
});
}

function clearCache(){
function clearCache() {

var options = {
title: 'Are you sure you want to clear all data cached ?',
Expand All @@ -35,9 +37,23 @@

/////////////

function clear(){
function clear() {
vm.clearing = true;
CacheFactory.get(defaultCacheName).removeAll();
$log.info('Default cache is now empty');
$log.info('HTTP cache is now empty');
ImgCache.clearCache(ok, throwErr);

/////////////

function ok() {
$scope.$apply(function () {
$log.info('Image cache is now empty');
// So we could read something at least
$timeout(function () {
vm.clearing = false;
}, 500);
});
}
}

}
Expand Down
4 changes: 3 additions & 1 deletion app/settings/tab-settings.jade
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ ion-view(view-title='Settings')
ion-toggle(ng-model='vm.settings.enableCache', toggle-class='toggle-positive')
| Enable Cache
ion-item(ng-click='vm.clearCache()')
button.button.button-assertive.button-small.button-block Empty cache
button.button.button-assertive.button-small.button-block
span(ng-if='vm.clearing') Clearing…
span(ng-if='!vm.clearing') Clear cache

0 comments on commit 67a64ea

Please sign in to comment.