Muse Reader Asks:
I'm trying to use cachedAfter in a query. I have tried cachedAfter="#dateAdd("d", 1, now())# but it doesn't seem to ever cache after a day has passed. What am I doing wrong? cachedwithin seems to work fine.
This is one of those obscure tags that gets very little use in the community. I confess to never actually having found a use for it in production. Still, it bears some looking at because it is a clever notion that might come in handy under certain circumstances. Here's a primer:
The cachedafter attribute sets up the query to only cache if the query event is occuring after the date and time specified. This means your value has to be constant enough so that the threshold is crossed at some point. For example, if the value is set to 4:30 in the afternoon today, the query will continue to run "live" until 4:30, but the first time after 4:30 the query is run it will be cached - and it will be served from the cache from then on until a new "cahcedafter" value is given - or until something else clears the cache like the FIFO buffer or a restart. But in the example of the muse reader above this will never happen. The value of cachedafter will always be 24 hours into the future and therefore the server will never have any reason to cache it.
Here's a good example of when cachedafter might be effective. The "big three" stock exchanges open at 8:30 and close at 3:00 each day. Let us suppose that you are serving stock quotes from a data source using cfquery. If you wanted to always serve live data when the markets were trading you might set up some code like this: