DataMgr SmartCache

Way back in January, I released the first Alpha build of DataMgr 2.2 (I still can't believe how long I have let development stretch out). In the announcement for that build, I mentioned a new experimental feature called "SmartCache", but I never explained what it was.

(What is DataMgr?)

Before I explain what SmartCache is, I should point out that it is only available in ColdFusion 8 and above.

SmartCache is best in situations where all of the data changes to a database are happening through DataMgr (though it can work when other data changes are made from ColdFusion). It also makes sense in systems where data is retrieved far more frequently than it is updated.

To enable SmartCache, pass a SmartCache argument to the init() method with a value of true.

<cfset Application.DataMgr = CreateObject("component","DataMgr").init(datasource="MyDSN",SmartCache=true)>

Once SmartCache is enabled, DataMgr will track when data is changed in the database. If DataMgr is asked to run a query that it has already run since the last change to data, it will just get the query from cache instead. This will save a trip to the database and enable quicker execution.

If any data has changed since the last time the query has run, it will run the query again. This is done universally rather than by table since any query could reference multiple tables by use of relation fields or custom SQL.

Internally, DataMgr calls the setCacheDate() function any time that it performs an operation that could change data in the database. If you make any data changes outside of DataMgr, you can just call the setCacheDate() (no arguments needed) to tell DataMgr about the change.

This is still experimental, but for some systems has the potential to provide some real performance improvements.

Related Blog Entries

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
Nice! :)
# Posted By John Whish | 11/17/08 6:50 AM
I love it! Thanks Steve. :o)
# Posted By Simon Bingham | 11/27/08 4:31 AM
BlogCFC was created by Raymond Camden. This blog is running version 5.8.001.