mgonto/restangular

Cache clearing problem

archasek opened this issue · 4 comments

Hi.

I have this run with cache config:

angular
    .module('app.main')
    .run(restangularRuns);

function restangularRuns ($cacheFactory, Restangular, apiConfig) {
    var cache = $cacheFactory('http');

    Restangular.setBaseUrl(apiConfig.BASE);

    Restangular.setDefaultHttpFields({ cache: true });
    
    Restangular.addResponseInterceptor(function (data, operation, what, url, response) {
        if (operation === 'put' || operation === 'post' || operation === 'delete') {
            cache.removeAll();
        }

        var extractedData = data.data;
        // var extractedData = response.data;

        return extractedData;
    });
}

Unfortunately I think that GET cache isn't cleared properly, as after e.g. POST request I don't see any changes (after going to a specific state) until I refresh the page.

I've done something similar, and I'm using

$cacheFactory.get('$http')

Does that work for you?

Works @bostrom ! Thank you very much.. :)

@archasek good 👍
Are you able to close this issue?

I don't think so :(