1

I need to to refresh the cache after i add new data to database.

angular.module('app').factory('myService', function ($http,$cacheFactory) {

  var profileCache=$cacheFactory('profiles');

  //get list of items
  function getItem(){
   var request=$http({
     method:'get',
     url:domain+'/api/v1/items/list',
     cache:profileCache,
     params:{
       action:'get'
     }
   });
   return(request.then(response.data));
 }
// Post items
 function addItem(item){
   var request=$http({
     method:'post',
     url:domain+'/api/v1/items/add',
     data:item
   });
   return(request.then(response.data));
 }
})

I want to refresh the cache once the item is added,so that the cache can have new changed data.

2
  • This might be helpful to you Refresh or invalidate the cache Commented May 5, 2016 at 9:23
  • @GitaramKanawade Yup saw it. Buy could not implement it as wished. Commented May 5, 2016 at 9:42

2 Answers 2

0

as you can read here

https://docs.angularjs.org/api/ng/service/$http

$http responses are not cached by default

but if you have particular environment and you need to prevent any caching you can add a date time to your request example

function getItem(){
   var d = new Date();
   var n = d.getDate();
   var request=$http({
     method:'get',
     url:domain+'/api/v1/items/list?' + n,
     cache:true,
     params:{
       action:'get'
     }
   });
   return(request.then(response.data));
 }
Sign up to request clarification or add additional context in comments.

Comments

-1

var $httpDefaultCache = $cacheFactory.get('$http');

2 Comments

The answer does not make any sense. Please add some description.
I suggest to add some explanation - see meta.stackoverflow.com/help/how-to-answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.