Yes, if we want to keep things simple actually static method is probably
it. Key is I don't see other usage of Cache factory class now so I agree
with Brian's 99% assement (it is also certainly true for PojoCache).
-Ben
-----Original Message-----
From: Brian Stansberry
Sent: Saturday, October 28, 2006 12:03 AM
To: Ben Wang; Manik Surtani
Cc: jbosscache-dev(a)lists.jboss.org
Subject: RE: [jbosscache-dev] Consistent factory method
I prefer both ;-) Perhaps add a class to o.j.c.factories that creates a
singleton DefaultCacheFactory and exposes static methods? If people
don't want to use it, that's fine, but it's there for the 99.9% use
case. An issue is what to name it.
Static is a bit easier to understand when using the MC as it eliminates
an extra bean instantiation.
Static:
<bean name="MyCacheConfig"
class="org.jboss.cache.config.Configuration">
....
</bean>
<bean name="MyCache">
<constructor factoryClass="org.jboss.cache.pojo.PojoCacheFactory"
factoryMethod="createInstance">
<parameter class="org.jboss.cache.config.Configuration"><inject
bean="MyCacheConfig"/></parameter>
<parameter>false</parameter>
</constructor>
</bean>
Instance:
<bean name="MyCacheConfig"
class="org.jboss.cache.config.Configuration">
....
</bean>
<bean name="MyCacheFactory"
class="org.jboss.cache.factories.DefaultCacheFactory"/>
<bean name="MyCache">
<constructor factoryMethod="createCache">
<factory bean="MyCacheFactory"/>
<parameter class="org.jboss.cache.config.Configuration"><inject
bean="MyCacheConfig"/></parameter>
<parameter>false</parameter>
</constructor>
</bean>
jbosscache-dev-bounces(a)lists.jboss.org wrote:
Ic. So what do other people prefer, if we can do it either way?
-----Original Message-----
From: Manik Surtani [mailto:msurtani@redhat.com]
Sent: Thursday, October 26, 2006 9:17 PM
To: Ben Wang
Cc: jbosscache-dev(a)lists.jboss.org
Subject: Re: [jbosscache-dev] Consistent factory method
Nothing more than the factory is a simple class. If user code wants
to wrap it in a singleton and create factory methods in the wrapper,
it is up to them. Just keeping things simple.
> Manik,
>
> This is a minor issue raised by Brian when he is constructing the
> bean file for AS5. Currently, we have slight way of creating a cache
> instance from the factory method.
>
> In Cache, we do:
>
> CacheFactory factory = new DefaultCacheFactory();
> CacheSPI tree = (CacheSPI) factory.createCache(c, false);
>
> While in PojoCache, we do:
> cache_ = PojoCacheFactory.createInstance(configFile, false);
>
> Nothing wrong with both approaches but maybe we should be consistent
> in both cache instances. And I don't mind to switch if needed. For
> me, the reason that I did it in the first place is I don't forsee a
> pluggable cache instance for PojoCache. And if needed, another
> Factory can be used as well.
>
> I thought originally with your approach, there is more control over
> the lifecycle methods. But now it is probably not needed there. Any
> other reason to stick with your approach?
>
> Thanks,
>
> -Ben