Potential OCM / DI issue

We have built out a ServiceFactory. In the service factory object,
which is cached via the OCM, we have dependency injections for other
objects. Here's a sample:

<cfcomponent name="serviceFactory"
     hint="I am responsible for providing an interface to retreive
services."
     output="false"
     extends="baseService"
     cache="true">

  <cfproperty name="companyService" type="model:companyService"
scope="instance" />

  <cffunction name="getCompanyService" access="public" output="false"
returntype="any">
    <cfreturn instance.companyService />
  </cffunction>
</cfcomponent>

So, we are getting about 3 million hits a day on this app, so we're
hitting the system pretty heavy. Now, I can understand that when the
cache gets reaped and companyService is no longer available that our
service factory has no mechanism to see that the object is dead and
recreate it via getModel(). That's a flaw I can acknowlege.

What I don't understand is why when I call getCompanyService() that I
ended up with the "_NOTFOUND" string from the ColdboxOCM.get()
function.

I would think that serviceFactory.instance.companyService would point
to a dead object, but the fact that it returns "_NOTFOUND" seems to
imply that my reference pointer of instance.companyService is pointing
to the OCM.get() function instead of the object.

Is this an accurate assessment? If I'm understanding this correctly,
it would seem to me that dependency injection is a bad idea for us and
that the service factory's getCompanyService() should return
getModel('companyService) and not instance.companyService and that we
shouldn't even BOTHER with dependency injection.

Thoughts anyone?

- Will B.

Will, is the company service a time persisted service object or a singleton?

Luis F. Majano
President
Ortus Solutions, Corp

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

The CompanyService itself is cached, persistent. We don't specify any
timeout, but rather we use whatever default we have set up.

I'm sure it's getting reaped at some point, under heavy load. My
question isn't so much "why are we losing it", but rather "when we
lose it, why are we getting '_NOTFOUND_' as the return?" I would
expect undefined or an error or just about anything else. Only the
CBOCM.get() returns the "_NOTFOUND_", which is why I keep thinking I'm
getting a pointer, on the initial DI, to the "function call" as
opposed to the "function call's return value", if that makes any
sense.

The _NOT_FOUND is sent back by the cache. Now, if you are using time persisted objects, you cannot wire them like normal depenendencies, as they can expire, thus the side effect you are seeing.

You have to call the factory to give you the bean whether its cached or not. Basically you have to NOT use the injection but rather a getModel() call.

Luis F. Majano
President
Ortus Solutions, Corp

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

It actually seems that the problem is between the ocm.lookup('key')
and the next line of return ocm.get('key') that garbage collection or
CB reaping has removed the object.

That's the best thing we've come up with.

Also...is there a way to get transient, non-cached objects to NOT show
up as misses in the Cache monitor?