Hi Denny,
So what it sounds like is essentially my ‘cacheKey’ would be used as the
depends on but would be hashed along with say the page name, so where you
have pageFragment = cacheGet I would set say the page name so I might have
something like
‘getFreeForm_’ & hash( cacheKey)
This would check if there is a cache, if not creates one otherwise get that
cached item
Correct?
I really should have said this to begin with but the way I use the cache
in ACF is like this
Per the ACF docs the useQuerString and the dependsOn tags used togeather
will generate a new template cache based on the querystring and the depends
on
per the docs for querystring.
"If true, generates a template cache ID that includes the query string.
This means that a new template cache is created whenever the query string
changes.
If set to true, the attribute dependson considers the URL parameters
defined in the query string as well to generate template caches.
Also see the Usage section"
And for the depends on
A comma separated list of variables. If any of the variable values change,
ColdFusion updates the cache. This attribute can take an expression that
returns a list of variables.
The code you mentioned above will cache the page based on a hash of the
cacheID, would expanding your code to grab the querystring AND cachekey
essentially do the same thing as I’m doing now?
Thanks!On Tuesday, October 18, 2016 at 7:56:03 AM UTC-7, Denard Springle wrote:
Not knowing your application structure, your database structure, or what
you’re trying to accomplish with either… I’ll take a stab at helping you
as best I can anyway
dependsOn doesn’t generally expire any cached data I don’t believe, it
simply checks the cache to see if a cached object exists that matches the
dependsOn values. Given that, and given the little bit of information
you’re provided about your environment, I’d say something along the lines
of the following would get you going in the right direction…
// get your cache id from the database based on the page id
qGetData = DAO.getData( pageId );
// get the cached data from the cache
pageFragment = cacheGet( ‘pageFragment_’ & hash( qGetData.cacheId &
serializeJson( URL ) ) );
// check if it is null
if( isNull( pageFragment ) ) {
// it is null (so the cached data doesn’t exist), generate the page
fragment with a function
pageFragment = generatePageFragment();
// and save the page fragment to the cache (for the next request)
cachePut( ‘pageFragment_’ & hash( qGetData.cacheId & serializeJson( URL )
), pageFragment, createTimeSpan( 30, 0, 0, 0 ), createTimeSpan(30, 0, 0, 0
) );
}
// output the page fragment
writeOutput( pageFragment );
In short, you try to get the cached object using a combination of your
cache key (cacheId) and whatever scope you’re trying to capture dependsOn
values from now (assuming the URL scope, but could be FORM or, if using a
framework, rc scope) and if it returns null then it doesn’t exist, so you
generate the output, save it to the cache (for the next request) and output
the generated content. If it isn’t null, then you have the cached version
already and just output that.
HTH
– Denny