Skip navigation
Currently Being Moderated

How do I know hold old a database cache is?

Nov 15, 2011 3:12 PM

Tags: #cache #caching

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.

 
Replies
  • Dave Watts
    747 posts
    Mar 11, 2003
    Currently Being Moderated
    Nov 24, 2011 4:50 PM   in reply to Grant

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Jan 19, 2012 2:17 AM   in reply to Grant

    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

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points