Copy link to clipboard
Copied
I'm caching a database query since it's a lot of data but I want to output to the user if the data is fresh (just came from the database right now), or it's cached. If it's cached, I want to tell them how long ago it came from the database. I tried to use CacheGetAllIds (and then CacheGetMetadata) but the array is empty. Where I can find this information?
Thanks.
Copy link to clipboard
Copied
You can cache database queries in Session, Application or Server scopes, and store the time you created the variable in the same scope.
Dave Watts, CTO, Fig Leaf Software
Copy link to clipboard
Copied
Just to revive this old thread. I was busy with a related subject (monitoring), when I stumbled on it.
You should write code that logs in to the ColdFusion Administrator via an adminapi object. Then create a ServerMonitoring object on which to call getCachedQueries().
Steps:
(1) Enable Monitoring, Memory Monitoring and Profiling in the Administrator. That is required for the function getCachedQueries to work.
(2) Run a CFM page, say, cachedQueries.cfm, that contains the following code:
<cfscript>
/*Log in to ColdFusion Administrator (using your own password, naturally)*/
adminObj = createObject("component","cfide.adminapi.administrator");
adminObj.login("my_CF_Admin_password");
/*Instantiate the servermonitoring object*/
myObj = createObject("component","cfide.adminapi.servermonitoring");
/*Get structure(array?) containing details of each cached query*/
cachedQueries = myObj.getCachedQueries();
</cfscript>
<cfdump var="#cachedQueries#">
The documentation says this will dump the details of all cached queries as a structure having the following keys:
LASTTIMEEXECUTED: The time at which the query was executed
SIZE: The size of the query in bytes
EXECUTIONTIME: The time taken for the query to execute
QUERYNAME: The name of the query
DSN: The datasource name
SQL: The SQL for the query
TEMPLATEPATH: The path to the template on which the query was issued
TIMETAKEN:The time taken for the query to execute upto this call in milliseconds
LINENUMBER: The line number on the template where the query was issued
FUNCTIONNAME: The name of the function in which the query was issued, if any
EXECUTIONCOUNT: The number of times the query has been executed