Hi
My client's REST service returns a huge amount of metadata but my app only
requires a very small number of fields from it. Rather than caching the
entire response, I would like to just copy the fields I need and cache this
reduced data instead. I had hoped I could do something like the function
below, with the return data from transformResponse being cached instead but
unfortunately it's the entire response that gets cached.
Does anyone have a suggestion as to how I could best implement this?
var cacheTest = function ( ) {
return $http ({
method: 'GET',
url: ...REST URL...,
cache: true,
transformResponse: function ( data, headers ) {
var json = JSON.parse ( data );
// this contains the fields I wish to copy from the original response data
var newData = {
id: null,
title: null,
display: null
};
// deep copy each of the required fields into my new response object. The
original response data will be discarded in the finally
for ( var field in newData ) {
if ( json.hasOwnProperty ( field ) ) {
newData[field] = angular.copy ( json[field] );
}
}
return newData;
}
})
.then ( function ( response ) {
return response.data;
})
.finally ( function ( ) {
// dispose of the original response data so
json = data = headers = response = null;
});
}
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.