How can I prevent caching in angular?
I want to prevent caching in angular. For this, I set the cache property to false. After that, I request the same url. But didn't send this request to my server. The code used to prevent
$http({
cache : false,
method: "GET",
url :"myurl";
}).success(function(data) {
}).error(function(data) {
});
And the code used to delete the cache is
var $httpDefaultCache = $cacheFactory.get('$http');
$httpDefaultCache.remove('myurl');
$http({
cache : false,
method: "GET",
url :"myurl";
}).success(function(data) {
}).error(function(data) {
});
can help me? You are welcome,
+3
source to share
1 answer
You can pass a bogus parameter in the URL to make the URL unique by adding data to it. Passing the parameter dummy
in an array params
doesn't hurt the $http
get call .
$http({
method: 'GET',
url: 'myurl',
params: { 'dummy': new Date().getTime() }
})
This will ensure that no caching is done for your URL.
The best option would be to disable server side caching link here
+2
source to share