D
D
Dmitry Skryabin2014-02-16 12:23:53
Angular
Dmitry Skryabin, 2014-02-16 12:23:53

What is the correct way to use the cache in ng-resource so that it is up to date?

There is a User service:

settingsModule.factory('User', ['$resource',
  function($resource){
    var user = $resource( '/users/:Id', {}, {
        query: {method: 'GET', cache: true, isArray: true},
        get: {method: 'GET', cache: true, params: {Id: '@Id'}}
    });
    return user;
}]);

The general list of users and each user separately are cached. But if I change the data of one user (obtained from get), then the query will not determine that the data has changed and will return the stale data to me. You can, of course, contact ngCache directly and delete the /users request cache, but this is not interesting - you need to remember the request address. Are there any other ways to update the cache?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question