choose cache based on key

35 views
Skip to first unread message

Bsr S

unread,
Oct 21, 2014, 6:34:59 AM10/21/14
to angula...@googlegroups.com
Hi Json,

Is it possible to have a strategy like, all the partial requests are cached into local store and rest of the data request goes to session storage.

app.run(function ($http, DSCacheFactory) {

    DSCacheFactory('defaultCache', {
        storageMode: 'sessionStorage'
    });
	DSCacheFactory('partialCache', {
        storageMode: 'localStorage'
    });
    $http.defaults.cache =  ?? // DSCacheFactory.get('defaultCache');
});
if it is not directly supported, can one write a wrapper on cache put to select the appropriate cache based on key (say check for .html)

Thanks,
bsr.

Jason Dobry

unread,
Oct 21, 2014, 12:47:49 PM10/21/14
to angula...@googlegroups.com
$http can only use 1 cache at a time, so you'll have to do your own code-fu to dynamically change which cache the item is put into. I would write a full wrapper for the two caches.

something like this:

var wrapperCache = {
  put
: function (key, value) {
   
if (isPartial(key)) {
      partialCache
.put(key, value);
   
} else {
      defaultCache
.put(key, value);
   
}
 
},
 
get: ...,
  remove
: ...,
  etc
: ...
};


$http
.defaults.cache = wrapperCache;



-- 
Jason Dobry

NOTICE: This email message is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.
Reply all
Reply to author
Forward
0 new messages