cached views

Is there a way to turn off view caching for a dev environment?

I have tons of cached views similar to this sprinkled throughout an
application:

     renderView(view='sections/
dspHeader',cache=true,cacheTimeout="1440")

and I would love to have an environment setting to turn off view
caching while on my dev machines in the same way we can do wioth event
and/or handler caching... but I cannot seem to find one other than
executing a clearAllViews() in each request?

For development environment stuff, I often make a interceptor that is only registered within my dev environment. Then, you can clear the template cache at the start/end of each request.

You can see an example of some dev-only stuff on this blog post: http://aarongreenlee.com/share/coldfusion-coldbox-client-source/

I have a snippet from my ColdBox config showing how to register an interceptor only in a specific environment.

You can read about clearing the items from the cache here: http://wiki.coldbox.org/wiki/CacheBox.cfm (clearAll()) for example.

Thanks Aaron - I'll give your blog post a lookover!

I think a config setting similar to the handler and event caching bool
would be a great addition to the configure API. By the way
getColdBoxOCM().clearAllViews() on onRequestStart does *not* seem to
work...

In ColdBox 3 we have two cache regions: default ( for objects and data) and template (views and event caching). This provides flexibility to choose where items get stored and how and in what cache. Therefore, to interact you are talking to the wrong provider.

getColdBoxOCM(“template”) or
getCacheBox().getCache(“template”)

Thanks

Yeah you want to do something like this in your interceptor:

var cacheName = arguments.event.getTrimValue(“cbox_cacheName”,“default”); log.debug(“postProcess fired, clearing all views”); getColdboxOCM(cacheName).clearAllViews();

Thanks John... the interceptor works perfectly (that is once I changed
"default" to "template" in your first line of script)

I still think this would make a great boolean setting for the
Coldbox.cfc
Thanks!

Ack, sorry, I meant “template” :slight_smile:

To further enhance that interceptor, you could also make it do a check of the environment and conditionally clear the cache.

One technique I have used is when you set the view caching to set true based on a setting.

event.setView(name=”home”, cache= getSetting(“cacheViews”));

Then I can switch the cacheViews flag based on the environment pretty easily. I try (try being the key word) to do a setting for anything I would want to switch per environment because it is so nice and easy to do.

Curt

@Doug - what I did was to only register that interceptor in my
development() function on Colbox.cfc
@Curt - good idea... I will play with that idea too... see whch I like
the best!

The interceptor is only defined in the config for that environment, which is why I didn’t add that :slight_smile:

That's a neat idea Curt.

I like to clear the cache using the interceptor instead of stopping
caching completely as I want to know that the caching mechanism is
working. If I set caching off then it would never be used in
development only in production which would worry me. With the
interceptor I can also clear other things from the cache besides
objects in the template cache if I want to.

Also, when I cache views I tend to use the additional settings so I'd
have something like this:

event.setView( name='home', cache=true, cacheTimeout=30,
cacheLastAccessTimeout=10 )

It just seems odd to me to have the cache flag set false but still be
passing the caching arguments, but that's just me being pedantic :slight_smile:

- John