Package net.sf.ehcache

Examples of net.sf.ehcache.CacheManager


    @Override
    protected void setUp() throws Exception {
        URL config = getClass().getResource("test-ehcache.xml");
        assertNotNull(config);
        cacheManager = new CacheManager(config);
    }
View Full Code Here


    private CacheManager cacheManager;

    @Override
    protected void setUp() throws Exception {
        cacheManager = new CacheManager();
    }
View Full Code Here

    private static Log logger = LogFactory.getLog(EhCacheQueryCache.class);
   
    protected CacheManager cacheManager;
   
    public EhCacheQueryCache() {
        cacheManager = new CacheManager();
        init();
    }
View Full Code Here

        cacheManager = new CacheManager();
        init();
    }
   
    public EhCacheQueryCache(String configFile) {
        cacheManager = new CacheManager(configFile);
        init();
    }
View Full Code Here

     * After this period of time, we should only have 2 entries in the cache
     */
    @Test
    public void testCacheSetting() throws Exception
    {
        CacheManager cacheManager = null;

        try
        {
            long clockSkew = 1000; // 1 sec
   
            cacheManager = new CacheManager();
   
            cacheManager.addCache( "kdcReplayCache" );
            Cache ehCache = cacheManager.getCache( "kdcReplayCache" );
            ehCache.getCacheConfiguration().setMaxElementsInMemory( 2 );
            ehCache.getCacheConfiguration().setTimeToLiveSeconds( 1 );
            ehCache.getCacheConfiguration().setTimeToIdleSeconds( 1 );
            ehCache.getCacheConfiguration().setDiskExpiryThreadIntervalSeconds( 1 );

            ReplayCacheImpl cache = new ReplayCacheImpl( ehCache, clockSkew );

            int i = 0;

            // Inject 4 entries
            while ( i < 4 )
            {
                KerberosPrincipal serverPrincipal = new KerberosPrincipal( "server" + i + "@APACHE.ORG",
                    PrincipalNameType.KRB_NT_PRINCIPAL.getValue() );
                KerberosPrincipal clientPrincipal = new KerberosPrincipal( "client" + i + "@APACHE.ORG",
                    PrincipalNameType.KRB_NT_PRINCIPAL.getValue() );

                cache.save( serverPrincipal, clientPrincipal, new KerberosTime( System.currentTimeMillis() ), 0 );

                i++;
            }

            List<?> keys = ehCache.getKeys();

            // We should have 4 entries
            assertTrue( keys.size() != 0 );

            // Wait till the timetolive time exceeds
            Thread.sleep( 1200 );

            // then access the cache so that the objects present in the cache will be expired
            for ( Object k : keys )
            {
                assertNull( ehCache.get( k ) );
            }

            assertEquals( 0, ehCache.getKeys().size() );
        }
        finally
        {
            if ( cacheManager != null )
            {
                cacheManager.shutdown();
            }
        }
    }
View Full Code Here

            ConfigurationFactory.parseConfiguration(EHCacheManagerHolder.class.getResource("/test-ehcache.xml"));
           
        assertNotNull(conf);
        conf.setName("testCache");
       
        CacheManager manager1 = EHCacheManagerHolder.createCacheManager(conf);
        assertNotNull(manager1);
        CacheManager manager2 = EHCacheManagerHolder.createCacheManager();
        assertNotNull(manager2);
       
        manager1.shutdown();
        assertEquals(Status.STATUS_SHUTDOWN, manager1.getStatus());
       
        assertEquals(Status.STATUS_ALIVE, manager2.getStatus());
       
        manager2.shutdown();
        assertEquals(Status.STATUS_SHUTDOWN, manager2.getStatus());
       
    }
View Full Code Here

        cc.setName(key);
        return cc;
    }
   
    public static CacheManager getCacheManager(String confName, URL configFileURL) {
        CacheManager cacheManager = null;
        if (configFileURL == null) {
            //using the default
            cacheManager = findDefaultCacheManager(confName);
        }
        if (cacheManager == null) {
            if (configFileURL == null) {
                cacheManager = createCacheManager();
            } else {
                cacheManager = findDefaultCacheManager(confName, configFileURL);
            }
        }
        AtomicInteger a = COUNTS.get(cacheManager.getName());
        if (a == null) {
            COUNTS.putIfAbsent(cacheManager.getName(), new AtomicInteger());
            a = COUNTS.get(cacheManager.getName());
        }
        a.incrementAndGet();
        // if (a.incrementAndGet() == 1) {
            //System.out.println("Create!! " + cacheManager.getName());
        // }
View Full Code Here

        return ds;
    }

    public static net.sf.ehcache.CacheManager newEhcacheManager() {
        //Create a singleton CacheManager using defaults
        CacheManager manager = CacheManager.create();
        //Create a Cache specifying its configuration.
        Cache testCache = new Cache(
                new CacheConfiguration("Author", 7)
                        .memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.LFU)
                        .eternal(false)
                        .timeToLiveSeconds(60)
                        .timeToIdleSeconds(30)
//                        .diskExpiryThreadIntervalSeconds(0)
                        .persistence(new PersistenceConfiguration().strategy(PersistenceConfiguration.Strategy.LOCALTEMPSWAP)));
        manager.addCache(testCache);

        return manager;
    }
View Full Code Here

  public void afterPropertiesSet() throws IOException, CacheException {
    logger.info("Initializing EHCache CacheManager");
    if (this.configLocation != null) {
      InputStream is = this.configLocation.getInputStream();
      try {
        this.cacheManager = (this.shared ? CacheManager.create(is) : new CacheManager(is));
      }
      finally {
        is.close();
      }
    }
    else {
      this.cacheManager = (this.shared ? CacheManager.create() : new CacheManager());
    }
    if (this.cacheManagerName != null) {
      this.cacheManager.setName(this.cacheManagerName);
    }
  }
View Full Code Here

   
    bind(CacheManager.class).annotatedWith(UserCacheAware.class).toProvider(new Provider<CacheManager>() {

      @Override
      public CacheManager get() {
        return new CacheManager(ClassUtil.getResource("ehcache-smbiz-persist.xml"));
      }
    }).in(Scopes.SINGLETON);
   
    install(new SmbizEntityServiceFactoryModule());
   
View Full Code Here

TOP

Related Classes of net.sf.ehcache.CacheManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.