Caching objects onApplicationStart

Hi folks,

In Luis’s CB book he references a technique of storing objects within the cache onApplicationStart(). I following the example code like so:

public boolean function onApplicationStart() output=false{
//Load ColdBox
loadColdBox();

//load data which rarely changes and prepare to place in ColdBox cache
var qBloodTypes = getPlugin(“ioc”).getBean(“BloodtypeService”).list();

//persist data in the cache until the application reinitializes
getColdBoxOCM().set(‘qBloodTypes’,qBloodTypes,0);

return true;
}

When I force the onApplicationStart() to fire I receive an error back indicating that getPlugin is undefined. I assumed that by executing loadColdBox() prior to setting up the objects was the right move since getPlugin() is part of the CB framework. Any ideas why this error would be occurring?

Thanks much.

Nolan

You running version 2.6.3? Book and, presumably, examples are up to 2.6.3.

- Gabriel

For what it's worth, I prefer to do these things in an Interceptor.
You can create a custom interception point that is also triggered by
the "configuration" method in the interceptor.

No right or wrong way.

Keep it up!

Aaron Greenlee

http://aarongreenlee.com/
Twitter: aarongreenlee

Not only that it is the application start handler not the application.cfc onapplicationstart method

Thanks Aaron,

Would you happen to have an example of how you achieve with an interceptor?

Luis, just saw your email come through. Thanks for clarifying. So I assume you're meaning within the configure() method of Coldbox.cfc?

Thanks all. I'm (slowly) getting up to speed on this!

Best,

Nolan

Or rather, would this be achieved by setting the applicationStartHandler var within coldbox.cfc…

//Implicit Events
defaultEvent = “General.login”,
requestStartHandler = “”,
requestEndHandler = “”,
applicationStartHandler = “Main.onAppInit”,
applicationEndHandler = “”,
sessionStartHandler = “”,
sessionEndHandler = “”,
missingTemplateHandler = “”,

and then configuring the vars onAppInit within Main.cfc

//load data which rarely changes and prepare to place in ColdBox cache var qBloodTypes = getPlugin("ioc").getBean("BloodtypeService").list();

//persist data in the cache until the application reinitializes
getColdBoxOCM().set(‘qBloodTypes’,qBloodTypes,0);

Thanks.

Nolan

Nolan,

This is my preferred way of doing it. As Aaron said. Lot of ways to do the same thing.

Curt Gratz

Computer Know How

Thanks all.

Got it to work using Main.onAppInit.

I'm loving CB Luis! Super powerful!

Thanks.

Nolan