Thursday, 15 April 2010

caching - Worklight adapter reponse header cache control -



caching - Worklight adapter reponse header cache control -

i created http adapter.

that work fine.

this sample of rss getstories

function getstories(interest) { path = getpath(interest); var input = { method : 'get', returnedcontenttype : 'xml', path : path }; homecoming wl.server.invokehttp(input); }

i successful response header info follows:

cache-control →no-cache, no-store, must-revalidate content-length → content-length length of response body in octets (8-bit bytes) 9220 content-type →application/json; charset=utf-8 date →thu, 19 jun 2014 12:46:12 gmt expires →sat, 26 jul 1997 05:00:00 gmt p3p →policyref="/w3c/p3p.xml", cp="cao dsp cor cura adma deva our ind phy onl uni com nav int dem pre" x-powered-by →servlet/3.0

and client app reads http header info , hence doesn't cache response.

how can enable cache? if notice "expires" of 1997, don't know how , taking date.

thanks in advance.

worklight homecoming headers back-end services unchanged. if nevertheless alter headers, can in worklight adapter. inspiration solution below got article: handling backend responses in adapters.

i created standard worklight cnn adapter (new -> worklight adapter -> http adapter) , gave name (changeheadersadapter).

then in changeheaderadapter-impl.js changed getstories procedure to:

function getstories(interest) { path = getpath(interest); var input = { method : 'get', returnedcontenttype : 'xml', path : path }; var backendresponse = wl.server.invokehttp(input); if(backendresponse.issuccessful && backendresponse.statuscode == 200){ //for simplicity, considering 200 valid //do interesting info backendresponse.responseheaders['cache-control'] = "public, max-age=0"; } else{ backendresponse.issuccessful = false; //overwrite failure } homecoming backendresponse;

}

as see changed cache-control parameter "public" (normally homecoming "private").

i guess answers question. please allow me know.

caching worklight cache-control worklight-adapters worklight-server

No comments:

Post a Comment