Package net.sf.ehcache

Examples of net.sf.ehcache.CacheManager


      log.debug("Starting EhCacheProvider cache");
      try
      {
         if (getConfiguration() != null)
         {
            cacheManager = new CacheManager(getConfigurationAsStream());
         }
         else
         {
            cacheManager = new CacheManager();
         }
      }
      catch (net.sf.ehcache.CacheException e)
      {
         throw new IllegalStateException("Error starting EHCache Cache", e);
View Full Code Here


            cachePath = FileUtils.getTempDirectoryPath();
        }

        cc.getDiskStoreConfiguration().setPath( cachePath );
        cacheManager = new CacheManager( cc );

        initialized = true;
    }
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

               log.warn("Attempt to restart an already started EhCacheProvider. Use sessionFactory.close() "
                         + " between repeated calls to buildSessionFactory. Using previously created EhCacheProvider."
                         + " If this behaviour is required, consider using net.sf.ehcache.hibernate.SingletonEhCacheProvider.");
               return;
          }
          manager = new CacheManager();
          _CacheManager = new Hashtable<String, EhCache>();
     }
View Full Code Here

                cacheManager = CacheManager.getCacheManager( getName() );
            }
        }
        else
        {
            this.cacheManager = new CacheManager( new Configuration().name( getName() ).diskStore(
                new DiskStoreConfiguration().path( getDiskStorePath() ) ) );
        }

        boolean cacheExists = cacheManager.cacheExists( getName() );
View Full Code Here

  public EhCacheCacheProvider(@Named("shindig.cache.ehcache.config") String configPath,
                              @Named("shindig.cache.ehcache.jmx.enabled") boolean jmxEnabled,
                              @Named("shindig.cache.ehcache.jmx.stats") boolean withCacheStats,
                              GuiceServletContextListener.CleanupHandler cleanupHandler)
      throws IOException {
    cacheManager = new CacheManager(getConfiguration(configPath));
    create(jmxEnabled, withCacheStats);
    cleanupHandler.register(this);
  }
View Full Code Here

            String configurationResourceName = null;
            if (properties != null) {
                configurationResourceName = (String) properties.get( Environment.CACHE_PROVIDER_CONFIG );
            }
            if ( StringHelper.isEmpty( configurationResourceName ) ) {
                manager = new CacheManager();
            } else {
                URL url = loadResource(configurationResourceName);
                manager = new CacheManager(url);
            }
        } catch (net.sf.ehcache.CacheException e) {
      //yukky! Don't you have subclasses for that!
      //TODO race conditions can happen here
      if (e.getMessage().startsWith("Cannot parseConfiguration CacheManager. Attempt to create a new instance of " +
View Full Code Here

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

public class EhCacheTest extends DirectMemoryOsgiTestSupport {

  @Test
  public void testPutRetreive() {
    Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
    CacheManager cacheManager = CacheManager.getInstance();
    Ehcache ehcache = cacheManager.getEhcache("testCache");

    ehcache.put(new Element("testKey", "testValue"));
    stats(ehcache);
    Assert.assertEquals("testValue", ehcache.get("testKey").getObjectValue());
  }
View Full Code Here

  }

  @Test
  public void testSizing() {
    Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
    CacheManager cacheManager = CacheManager.getInstance();
    Ehcache ehcache = cacheManager.getEhcache("testCache");
    for (int i = 0; i < 30000; i++) {
      if ((i % 1000) == 0) {
        System.out.println("heatbeat " + i);
        stats(ehcache);
      }
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.