commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Romain Manni-Bucau <rmannibu...@gmail.com>
Subject Re: JCS jcache examples specifically with spring caching
Date Wed, 25 Jan 2017 14:52:33 GMT
Hi

this is not the way to use JCache in spring, Use spring method factory bean
to do:

provider=Caching.getCachingProvider(), destroy method will be close()

then you can do through the same factory:

// the provider can give you default values for these params if you want
manager=provider.getCacheManager(configUri, classloader)

then if you want to create a cache:

// here javax.cache.configuration.MutableConfiguration will be spring
friendly
cache=manager.createCache(name, configuration)

Don't try to use directly JCS implementation, this is not intended to be
done and not supposed to stable in term of user API (this is really an
internal of JCS where JCache API is public for these classes)

Let me know if you need some help for next step (ie using
the methodinvokingfactorybean)



Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> |  Blog
<https://blog-rmannibucau.rhcloud.com> | Old Blog
<http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
LinkedIn <https://www.linkedin.com/in/rmannibucau> | JavaEE Factory
<https://javaeefactory-rmannibucau.rhcloud.com>

2017-01-25 15:48 GMT+01:00 Tim Cronin <tim@outboundengine.com>:

> I'm trying to leverage Spring caching using jcs cache
> the javadocs show only ctor for the JCSCachingManager.
> https://commons.apache.org/proper/commons-jcs/commons-
> jcs-jcache/apidocs/src-html/org/apache/commons/jcs/jcache/
> JCSCachingManager.html#line.83
>
> but i pass in what seems more like default values
>
> public static void main(String[] args) throws Exception
>   {
>    JCSCachingProvider provider = new JCSCachingProvider();
>    Properties props = new Properties();
>
>    CacheManager cacheMgr = new JCSCachingManager(provider,
>        JCSCachingProvider.DEFAULT_URI,
>        Thread.currentThread().getContextClassLoader(),
>        props);
>
> //... do cache stuff...
>
>    cacheMgr.close();
>
>   }
>
> I'm trying to fit this into an existing webapp that uses xml base
> configuration
> and having to set the defaults seems problematic, I'd have to wrap it to
> get
> proper current class load or use system which doesn't map to webapp loader
>
> Is there any reason for not having a default Ctor?
>
> <!-- cjs cache manager setup -->
>     <beans:bean id="cache.provider" class="org.apache.commons.jcs.
> jcache.JCSCachingProvider"/>
>     <beans:bean id="cache.url" class="org.apache.commons.jcs.
> jcache.JCSCachingProvider.DEFAULT_URI"/>
>     <!--  this seems hacky should be a  -->
>     <beans:bean id="cache.classloader" class="java.lang.Class"
> factory-method="getSystemClassLoader" />
>     <beans:bean id="cache.properties" class="java.util.Properties"/>
>
>     <beans:bean id="cache.manager" class="org.apache.commons.jcs.
> jcache.JCSCachingManager">
>         <beans:constructor-arg ref="cache.provider" />
>         <beans:constructor-arg ref="cache.url" />
>         <beans:constructor-arg ref="cache.classloader" />
>         <beans:constructor-arg ref="cache.properties" />
>     </beans:bean>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message