Force Angular clear $ cacheFactory after some action

Thus, we cache the values ​​from the drop-down list in the drop-down help module in this way

var cache = new CacheFactory('DropDownResource', {
      maxAge: 3600000,
      deleteOnExpire: 'aggressive',
      capacity: 5,
      storageMode: 'sessionStorage'
    });

And then in the $ http callback we save the data for the dropdown in this way

cache.put('dataForDropDown', data);

In another module, we can change user settings, especially for changing the language. After this step I need to clear the cache. Because when the user changes the language and goes to the page with a drop-down list, he wants to see a drop-down list with the desired language.

So, on the page with a drop-down list, we need to send a call to the server again. To do this, we need to clear the cache after changing the language.

How can we do this?

I am trying to execute this code in a dropdown module.

var cache = $cacheFactory ('dataForDropDown'); cache.remove( 'dataForDropDown');

. , dataForDropDown . ,

+4
1

, $cacheFactory('name') . , removeAll, - :

angular.module('superCache')
  .factory('superCache', ['$cacheFactory', function($cacheFactory) {
    return $cacheFactory('super-cache');
  }]);

factory . factory superCache . , removeAll. remove(key), (, angular) .

+2

Source: https://habr.com/ru/post/1606344/


All Articles