Luis, ok i'm caching the data output per user. However, my event
handler is calling the API (cfhttp to 3rd party webservice) on every
page load. So to really increase performance if i could only call the
API every 60 mins that would be best or lastAccesstimeout at 30 mins.
It starts with a little ajax, and as you can see I'm only caching the
viewlet:
HOMEPAGE HTML
<div id="advanced-metrics"></div>
<script type="text/javascript">
$('#advanced-metrics').load('/index.cfm/WebService/getMetrics?
layout=header');
</script>
WEBSERVICE HANDLER
<cfcomponent output="false">
<cfproperty name="CoreAPI" inject="model:CoreAPI">
<cffunction name="getMetrics" access="public" returntype="void"
output="false">
<cfargument name="Event" type="any">
<cfscript>
//Do Login Procedure.
var rc = Event.getCollection();
var DataStruct = StructNew();
var oSession = getPlugin("SessionStorage");
var oClient = getPlugin("ClientStorage");
var userID = oSession.getVar("userinfo.id");
DataStruct = CoreAPI.metrics(userID);
rc.metrics = StructNew();
rc.metrics.volume1 = DataStruct.vol1;
rc.metrics.volume2 = DataStruct.vol2;
rc.metrics.volume3 = DataStruct.vol3;
rc.metrics.volume4 = DataStruct.vol4;
Event.showdebugpanel("false");
Event.setLayout("Layout.Metrics");
</cfscript>
</cffunction>
</cfcomponent>
COREAPI MODEL
<cfcomponent output="false">
<!--- Dependencies --->
<cfproperty name="APIBaseURL" inject="coldbox:setting:APIBaseURL"
scope="instance" />
<cfproperty name="APIUser" inject="coldbox:setting:APIuser"
scope="instance" />
<cfproperty name="APIPass" inject="coldbox:setting:APIpass"
scope="instance" />
<cffunction name="metrics" access="public" returntype="struct"
output="false">
<cfargument name="sessionid" type="string" required="true">
<cfsavecontent variable="soapBody">
<cfoutput>
<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/
envelope/" xmlns:web="http://webservices.xx.com" xmlns:web1="http://
webservice.services.xx.com">
<soapenv:Header/>
<soapenv:Body>
<web:#arguments.method#>
<web:in0>#arguments.sessionid#</web:in0>
<web:in1>
<!--Optional:-->
<web1:password>#instance.APIPass#</web1:password>
<!--Optional:-->
<web1:userId>#instance.APIUser#</web1:userId>
</web:in1>
</web:#arguments.method#>
</soapenv:Body>
</soapenv:Envelope>
</cfoutput>
</cfsavecontent>
<cfhttp url="#instance.APIBaseURL#/services/ICustomWebServices"
method="post" result="apiResponse">
<!--- Most SOAP action require some sort of SOAP Action
header to be used. --->
<cfhttpparam type="header" name="SOAPAction" value=""/>
<!--- I typically use this header because CHTTP cannot handle
GZIP encoding. This "no-compression" directive tells the server not to
pass back GZIPed content. --->
<cfhttpparam type="header" name="accept-encoding"
value="gzip,deflate"/>
<!--- When posting the SOAP body, I use the CFHTTPParam type
of XML. This does two things: it posts the XML as a the BODY and sets
the mime-type to be XML. --->
<cfhttpparam type="xml" value="#trim(soapBody)#"/>
</cfhttp>
<cfset soapResponse = xmlParse( apiResponse )>
<cfset vol1 = xmlSearch(soapResponse, "//
*[name()='volume1']")>
<cfset vol2 = xmlSearch(soapResponse, "//
*[name()='volume2']")>
<cfset vol3 = xmlSearch(soapResponse, "//
*[name()='volume3']")>
<cfset vol4 = xmlSearch(soapResponse, "//
*[name()='volume4']")>
<cfset rtnStruct.vol1 = vol1>
<cfset rtnStruct.vol2 = vol2>
<cfset rtnStruct.vol3 = vol3>
<cfset rtnStruct.vol4 = vol4>
<cfreturn rtnStruct>
</cffunction>
</cfcomponent>
LAYOUT
<cfouput>#renderView(view='global/
volumemetrics',cache=true,cacheTimeout='60',cacheSuffix="#userID#")#</
VIEW
<cfoutput>
<table id="subheader" width="320" cellpadding="0" cellspacing="0"
border="0">
<tbody>
<tr>
<td
class="leftCell">#getResource("metrics.vol1")#: #rc.metrics.volume1#</
<td
class="rightCell">#getResource("metrics.vol2")#: #rc.metrics.volume2#</
</tr>
<tr>
<td
class="leftCell">#getResource("metrics.vol3")#: #rc.metrics.volume3#</
<td
class="rightCell">#getResource("metrics.vol4")#: #rc.metrics.volume4#</
</tr>
</tbody>
</table>
</cfoutput>