• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How do I know hold old a database cache is?

Explorer ,
Nov 15, 2011 Nov 15, 2011

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.

TOPICS
Database access

Views

996

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 24, 2011 Nov 24, 2011

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 19, 2012 Jan 19, 2012

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation