Cached RenderData Responses?

All,

I’m working on an API and have implemented caching in several stages to make things as fast as possible. The final caching step within my ColdBox Application Layer would be to serialize the data (in this case as JSON) and cache it within EHCache which I access via ColdBox. I was thinking of adding a flag to the Event.renderData() to denote that the data has already been marshaled so ColdBox could appropriately apply content headers and send the data on its way to the previous visitor.

Before applying this to the core, I wanted to see if there are any thoughts from the ColdBox team or the community.

I’ve thought about allowing my Webserver to cache this content and avoid CF entirely; however, I’ve opted to first validate the parameters and generate a cache-key based only on the valid and actionable paramaters in alphabeticale order to allow me to cache the desired response regardless of how messy the query to the API is.

What do you guys think? Is this something that you could benefit from? I’m trying to shave off every possible millisecond.

Blog post on all this is coming btw.

Thanks,

Aaron Greenlee
http://aarongreenlee.com/

renderData() already supports your own conversion mechanism. Type=plain, and then add your own content-type

Uh duh… :slight_smile: Thanks Luis. That proves your watching the forum :slight_smile:

To anyone interested, here is the code… I got caught up on wanting the renderData() method to set the header for me. Was not thinking out of the box yesterday…

if (!isNull(local.cachedResult))
{
prc.response.setBody(local.cachedResult);
prc.response.setStatusCode(200);
Event.setHTTPHeader(name=‘Content-Type’,value=‘application/json’);
Event.setHTTPHeader(name=‘X-API-Cached’,value=‘true’);
// Render our response
Event.renderData(
data=prc.response.getBody()
,type=‘plain’
,statuscode=prc.response.getStatusCode()
,statustext=prc.response.getStatusText()
);

return;
}