Hi,
I came across a situation where Session had too many variables which was getting through a Query. Logging was taking a long time and most of the Session Variables had Limited used only to show Charts on user activity just after Login.
I looked into 2 options for Limited Use Query.
1. Ehcache.
2. Saving as binary data file by using ObjectSave and ObjectLoad.
I came across a situation where Session had too many variables which was getting through a Query. Logging was taking a long time and most of the Session Variables had Limited used only to show Charts on user activity just after Login.
I looked into 2 options for Limited Use Query.
1. Ehcache.
2. Saving as binary data file by using ObjectSave and ObjectLoad.
Ehcache
You can enable Ehcache through CF Admin-> Server Settings->Caching.
Number of queries cached is 100 by default. You can increase it. If it increases maximum it will delete from the older one and save the new one in Ehcache region.
In my version CF 10 I have Ecache 2.6.6 JARS. Can have max 10000 Queries in Memory
Number of queries cached is 100 by default. You can increase it. If it increases maximum it will delete from the older one and save the new one in Ehcache region.
In my version CF 10 I have Ecache 2.6.6 JARS. Can have max 10000 Queries in Memory
<cfquery datasource="dsn" name="VARIABLES.getClient" cachedwithin="#createTimespan(1,0,0,0)#" >
SELECT TOP 10 cCompanyName FROM CLIENTS WHERE cCompanyName = 'company'
</cfquery>
<cfdump var="#VARIABLES.getClient#" >
Cached will be true. In Normal Queries it will be false
It will save in 'Ehcache' cache region with id '1234' for 1 day
Working
If Same query is ran within 1 day Database layer hitting is surpassed and will get a query object from Ehcahe region. Parameter used should be same & query plan should be same, then only it will get from Cache.
Putting in Different cache region
We can save in different cache region too.
We can put in CacheRegion with CacheId using
To retrieve Cached Query object
It will save in 'Ehcache' cache region with id '1234' for 1 day
Working
If Same query is ran within 1 day Database layer hitting is surpassed and will get a query object from Ehcahe region. Parameter used should be same & query plan should be same, then only it will get from Cache.
Putting in Different cache region
We can save in different cache region too.
<cfset cacheRegionNew('clients')>
<cfquery datasource="dsn" name="VARIABLES.getClient" cacheregion="clients" cachedwithin="#createTimespan(1,0,0,0)#" >
SELECT TOP 10 cCompanyName FROM CLIENTS WHERE cCompanyName = 'company'
</cfquery>
<cfdump var="#VARIABLES.getClient#" >
We can't get the above Cached query by using 'cacheGet' function. It will show 'undefined'.We can put in CacheRegion with CacheId using
<cfset cachePut(1234,getClient,createTimespan(1,1,1,0),'','clients')>
To retrieve Cached Query object
We can verify whether the CacheRegion or CacheID exists before getting Query object.
Saving Query as Binary In Data File
We can save Query object in Data File as Binary Format.We can relative path for saving it in file.
In 'Ehcahe' Cache region will be in Server Space. If the parameter is changing the Cached query will be used less. The Object Saved will be on Physical file as the Query runs it will be updated if we are saving it in Same page.
I went for 'Ehcache' option as it was very helpful in this particular case.
<cfif cacheRegionExists('Ehcache')>
<cfif cacheIdExists('1234','Ehcache')>
<cfdump var="#cacheGet(1234,'Ehcache')#" >
</cfif>
</cfif>
Saving Query as Binary In Data File
We can save Query object in Data File as Binary Format.We can relative path for saving it in file.
<cfquery datasource="rsa" name="VARIABLES.getClient">
SELECT TOP 10 cCompanyName FROM CLIENTS WHERE cCompanyName = 'company'
</cfquery>
<cfset objectSave(getClient,'../parent/client.txt')>
To retrieve it <cfdump var="#objectload('../parent/client.txt')#" >
In 'Ehcahe' Cache region will be in Server Space. If the parameter is changing the Cached query will be used less. The Object Saved will be on Physical file as the Query runs it will be updated if we are saving it in Same page.
I went for 'Ehcache' option as it was very helpful in this particular case.