[COLDBOX 3.8.1] Best practice for caching viewlets

I saw from some other posts that #runevent(event=“blah”,cache=true,cachetimeout=10)# does not cache the event because it is meant to cache the entire event (not just a portion of it), so I started reading up on viewlets.

The CB Guide offers something close to the following for caching viewlets:

`
public void function blah (event,rc,prc) {

`

var rc = event.getCollection();

rc.viewletQuery = //Do some kind of query here;

**return renderview(view="blah",cache=true,cachetimeout=10);**

}

This is fine that it caches the view, but it still runs that query before returning the cached view.

What would be a best practice for caching the business logic that is required to build the viewlet? I can build in a “cacheput” etc, but just wondering if there is a convention?

Also, there are links to this page http://wiki.coldbox.org/wiki/Layouts-Views_Viewlets_or_Widgets.cfm but there is nothing there in the wiki.

Thanks!!

Ken there is no need to do getcollection(), the rc is already passed in as an argument!

forgot to add. look into cachebox for what you need

There is nothing in the core in 3.8.1 to do that. You have to do it manually.

On 4.0.0 we are adding a runEvent( with caching ) params, so it will cache for you.

Luis Majano
CEO
Ortus Solutions, Corp
www.ortussolutions.com

ColdBox Platform: http://www.coldbox.org
ContentBox Platform: http://www.gocontentbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Social: twitter.com/ortussolutions | twitter.com/coldbox | twitter.com/lmajano | twitter.com/gocontentbox

Thanks Andrew, you are correct. That was just some scratch so I’m surprised it didn’t have more errors! :slight_smile:

Thanks Luis, as usual you are 2 steps ahead of me…

That wont error, it just means it is doing two calls to inflate the info into the RC scoped variable.

If you haven’t already check out ContentBox. It has a lot of tricks under the hood, that if you peer through the code you will learn a lot of tricks etc., but one thing you will notice for certain is how caching works with OCM at the moment.

Luis, good news that 4.0 will have it under the hood :slight_smile: