still playing around with the jcache impl (see attached)

I created the cache using jcache functionality but if I try to access it
via native jcs it shows the cache as empty.

so you're are unable to manage the caches via JCSAdmin.

but could have something misconfigured


public final class CacheImpl {

    /**
     * Document Me!!!
     * @param args
     */
    public static void main(String[] args) {
        JCSCachingProvider provider = new JCSCachingProvider();
        Properties props = new Properties();

        CacheManager cacheMgr = new JCSCachingManager(provider,

URI.create("file:///C:/Users/Tim/workspace/Jcache/conf/cache.ccf"),
            Thread.currentThread().getContextClassLoader(),
            props);

        JCSConfiguration<String, String> configuration = new
JCSConfiguration<>(new MutableConfiguration(), String.class, String.class);

        Cache<String, String> testCache = cacheMgr.createCache("test",
configuration);

        for(int cnt = 0; cnt < 200; cnt++) {
            testCache.put("key-" + cnt, "value-" + cnt);
        }

        for(int cnt = 0; cnt < 200; cnt++) {
            if(testCache.containsKey("key-" + cnt)) {
                System.out.println("hit key-" + cnt);
            } else {
                System.out.println("miss key-" + cnt);
            }
        }

        dumpJCache(testCache);
        dumpJCS("test");

        cacheMgr.close();
    }

    private static void dumpJCache(Cache<String, String> cache) {
        StringBuilder buff = new StringBuilder();
        try {
            buff.append("jcache: ").append(cache.getName()).append(" closed
").append(cache.isClosed()).append('\n');

            Iterator<Cache.Entry<String, String>> i = cache.iterator();

            while(i.hasNext()){
                Cache.Entry<String, String> entry = i.next();

buff.append("key[").append(entry.getKey()).append("]value[").append(entry.getValue()).append(
"]\n");
            }

        } catch (Exception e) {
            StringWriter out = new StringWriter(512);
            e.printStackTrace(new PrintWriter(out));
            buff.append(out.toString());
        }

        System.out.println(buff.toString());
    }

    private static void dumpJCS(String cacheName) {
        StringBuilder buff = new StringBuilder();
        try {
            CacheAccess<String, String> cache = JCS.getInstance(cacheName);

            buff.append("jcs:
").append(cache.getCacheAttributes().getCacheName()).append(" status
").append(cache.getStats()).append('\n');

            Set<String> keys = cache.getCacheControl().getKeySet();

            if(keys.isEmpty()) {
            } else {
                for(String key : cache.getCacheControl().getKeySet()){

buff.append("key[").append(key).append("]value[").append(cache.get(key)).append(
"]\n");
                }
            }

        } catch (Exception e) {
            StringWriter out = new StringWriter(512);
            e.printStackTrace(new PrintWriter(out));
            buff.append(out.toString());
        }

        System.out.println(buff.toString());
    }

cache.ccf:

##################################################################
# JCS cache configuration
#
# JCS homepage:  https://commons.apache.org/proper/commons-jcs/
##################################################################

##################################################################
# default mem cache settings
##################################################################
jcs.default=DC
jcs.default.cacheattributes=org.apache.commons.jcs.engine.CompositeCacheAttributes
jcs.default.cacheattributes.MemoryCacheName=org.apache.commons.jcs.engine.memory.lru.LRUMemoryCache
jcs.default.cacheattributes.UseMemoryShrinker=true
jcs.default.cacheattributes.MaxMemoryIdleTimeSeconds=3600
jcs.default.cacheattributes.ShrinkerIntervalSeconds=300
jcs.default.cacheattributes.MaxSpoolPerRun=64
jcs.default.cacheattributes.DiskUsagePatternName=UPDATE

##################################################################
# default element attributes
##################################################################
jcs.default.elementattributes=org.apache.commons.jcs.engine.ElementAttributes
jcs.default.elementattributes.MaxLife=-1
jcs.default.elementattributes.IdleTime=-1
jcs.default.elementattributes.IsEternal=true
jcs.default.elementattributes.IsSpool=true
jcs.default.elementattributes.IsRemote=false
jcs.default.elementattributes.IsLateral=false

##################################################################
# default disk cache settings
##################################################################
jcs.auxiliary.DC=org.apache.commons.jcs.auxiliary.disk.indexed.IndexedDiskCacheFactory
jcs.auxiliary.DC.attributes=org.apache.commons.jcs.auxiliary.disk.indexed.IndexedDiskCacheAttributes
jcs.auxiliary.DC.attributes.DiskPath=${user.home}/test-cache/
jcs.auxiliary.DC.attributes.MaxPurgatorySize=512
jcs.auxiliary.DC.attributes.MaxKeySize=8096
jcs.auxiliary.DC.attributes.OptimizeAtRemoveCount=256
jcs.auxiliary.DC.attributes.OptimizeOnShutdown=true
jcs.auxiliary.DC.attributes.EventQueueType=POOLED
jcs.auxiliary.DC.attributes.EventQueuePoolName=disk_cache_event_queue

##################################################################
# Disk Cache pool
##################################################################
thread_pool.disk_cache_event_queue.boundarySize=50
thread_pool.disk_cache_event_queue.useBoundary=true
thread_pool.disk_cache_event_queue.maximumPoolSize=30
thread_pool.disk_cache_event_queue.minimumPoolSize=4
thread_pool.disk_cache_event_queue.keepAliveTime=3500
thread_pool.disk_cache_event_queue.startUpSize=4
thread_pool.disk_cache_event_queue.whenBlockedPolicy=RUN

##################################################################
# test
##################################################################
jcs.region.test.cacheattributes.MaxObjects=100
jcs.region.test.elementattributes.IsEternal=false
jcs.region.test.elementattributes.MaxLife=2000000
jcs.region.test.elementattributes.IdleTime=1800



On Wed, Jan 25, 2017 at 8:48 AM, Tim Cronin <[email protected]> wrote:

> 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>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to