[coldbox-3.8.0] Does runEvent() utilize event caching when executed from a handler?

I’ve got some unexpected behavior occurring with event caching and want to know if this is expected behavior.

When I execute an event via URL (top level framework request) for which cache=“true” is set, the expected occurs; the event is run, stored in template cache, and I’ve seen the cache key generated and so forth.

However, when I execute that same event via the runEvent() method from a different action in a handler, no cache key is set for the event in the template cache, and it fully executes every time.

Is this expected behavior? I couldn’t find in the documentation whether or not to expect this.

Thanks,
Adam

Event caching is only implmeneted at the top level for the “outer” event that is executed. It is based on the request collection for that request and includes things like the status code, HTML output from layouts and views rendered. I’m not sure what event caching would do for a runEvent() call-- especially one that doesn’t even return a value. What would it cache?

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Thanks a ton for clearing that up for me, I can now strategize around this knowledge.

As for what it would cache, I was hoping it would cache a “widget” style content chunk for me, as explained in the Executing Events section of the CB Wiki. In my use case I have an event that fetches data from the model and passes it (usually three items) to a view that renders the markup for it. The results are a content component “widget” that resides in a sidebar on several web pages. I could cache the view alone, however this doesn’t save the handler action from executing the model calls. :confused: I can’t cache the top level event here in the same way because there’s some user-specific data rolled up. I want to cache that per user, but cache my widget across the application.

Any suggestions as to how to structure this? I haven’t ventured into modules much, I wonder if there’s a solution in there for me. Maybe I could hit the widget via XHR… not optimal though.

  • Adam

The in-built caching is meant to get you going in simple situations, but there’s nothing keeping you from doing your own manual caching inside the event with CacheBox.

If you have many events to cache and they all use the same inputs, look at an AOP-style approach like the CacheBack aspect on ForgeBox:

http://www.coldbox.org/forgebox/view/CacheBack

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

You can also use the aroundHandler() or around action methods in a handler that can wrap your internal event calls as well.
http://wiki.coldbox.org/wiki/EventHandlers.cfm#Around_Advice_Intercpetors

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

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

Social: twitter.com/lmajano facebook.com/lmajano

Great suggestions, all of them. Thanks for the feedback!

  • Adam