ColdSpring and ColdBox IOCObjectCaching

This weekend I had a ColdSpring singletons caching problem. Like all caching problems, sometimes they occur, sometimes they do not......pfff......very difficult to reproduce.

ColdSpring threw errors on the method addBeanToSingletonCache in abstractBeanFactory.cfc. This method tries to store a singleton object in cache and if already exists, throws an error.

I asked Luis for help on this and he came up with the following answer/solution:

It seems that ColdSpring 1.1 had errors of that sort. I would try the 1.2 nightly build. What happens is that ColdSpring caches whenever a bean says singleton=true.  Now, you can go into ColdBox advanced mode and use IOCObjectCaching.  This basically means that all objects produced from ColdSpring become cached in the coldbox cache. So for example, in ColdSpring you say singleton=false, so ColdSpring just produces it, then on  the cfcomponent metadata, you set the cacheTimeout=0 so it becomes a singleton in the coldbox cache. Then whenever you call for it from the ioc plugin, you just get it from the ColdBox cache and not ColdSpring anymore.

Luis' solution works like a charm. All caching is done by ColdBox now!!

Comments
Sana's Gravatar Hi Ernst,

you always rock man. Thats really cool way to cache the coldspring objects.
# Posted By Sana | 3/3/08 11:58 AM
Ernst van der Linden's Gravatar Sana thanks, but credits go to Luis........like always :-)
# Posted By Ernst van der Linden | 3/3/08 2:03 PM
Luis Majano's Gravatar You just have to be careful when dealing with dependencies Ersnt. Because let's say you have a UserService and a SecurityService.

Now the SecurityService has a dependency on the UserService and the UserService can act on its own. If you set the singleton=false on the UserService, and you ask for it, Coldpsring creates it for you, gives it to you, ColdBox caches it and wallah. Cool right. Well, now you ask for a securityService, then Coldspring has to recreate the UserService because its not a singleton in the factory anymore.

You see the problem. So, you now have a problem that the IoC factory has to create the user service twice. Sometimes this is negligible. You just have to be aware of it.
# Posted By Luis Majano | 3/3/08 10:17 PM
Ernst van der Linden's Gravatar Thanks Luis, I get your point there.
# Posted By Ernst van der Linden | 3/3/08 10:32 PM
BlogCFC was created by Raymond Camden. This blog is running version 5.9.004.