Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Depends on what level of caching you want.</p> <p>You could depend on browser caching, in which case proper HTTP headers will suffice.</p> <p>You could depend on cache provided by $http in angular, in which case making sure the parameters you send up are the same would be sufficient.</p> <p>You could also create your own model caching along the lines of :</p> <pre><code>module.factory('ClientModel', function($http, $cacheFactory, $q){ var cache = $cacheFactory('ClientModel'); return { get : function(id){ var data = cache.get(id); if(data){ //Using $q.when to keep the method asynchronous even if data is coming from cache return $q.when(data); } else { //Your service logic here: var promise = $http.get('/foo/bar', params).then(function(response){ //Your model logic here var data = response; cache.put(id, data); return response; }, function(response){ cache.remove(id); return response; }); //Store the promise so multiple concurrent calls will only make 1 http request cache.put(id, promise); return promise; } }, clear : function(id){ if(angular.isDefined(id)){ cache.remove(id); } else { cache.removeAll(); } } } }); module.controller('ControllerA', function(ClientModel){ ClientModel.get(1).then(function(){ //Do what you want here }); }); module.controller('ControllerB', function(ClientModel){ ClientModel.get(1).then(function(){ //Do what you want here }); }); </code></pre> <p>Which would mean each time you request a client object with the same 'id', you would get the same object back.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload