Package net.sf.ehcache.config

Examples of net.sf.ehcache.config.CacheConfiguration


     
      for (final String cacheName : this.cacheManager.getCacheNames()) {
          final Cache cache = this.cacheManager.getCache(cacheName);
         
          if (null != cache && Status.STATUS_ALIVE.equals(cache.getStatus())) {
              final CacheConfiguration cacheConfiguration = cache.getCacheConfiguration();
              final Statistics statistics = cache.getStatistics();
             
              final CacheStatistics cacheStatistics = new CacheStatistics();
             
              cacheStatistics.hits = statistics.getCacheHits();
              cacheStatistics.misses = statistics.getCacheMisses();
              cacheStatistics.size = statistics.getObjectCount();
              cacheStatistics.maxSize = cacheConfiguration.getMaxElementsInMemory() + cacheConfiguration.getMaxElementsOnDisk();
             
              allCacheStatistics.put(cacheName, cacheStatistics);
          }
      }
     
View Full Code Here


      cache.put(element);
            return;
    }

    // using expiration method with a positive expiration, set that value as the element's TTL if it is lower than the configured cache TTL
    final CacheConfiguration cacheConfiguration = cache.getCacheConfiguration();
    final Element element = new Element(cacheKey, data);
        final long cacheTTL = cacheConfiguration.getTimeToLiveSeconds();
        if (expirationTime < cacheTTL) {
            element.setTimeToLive(expirationTime);
        }
    cache.put(element);
  }
View Full Code Here

    }
   
   
    public static CacheConfiguration getCacheConfiguration(String key,
                                                           CacheManager cacheManager) {
        CacheConfiguration cc = cacheManager.getConfiguration().getCacheConfigurations().get(key);
        if (cc == null && key.contains("-")) {
            cc = cacheManager.getConfiguration().getCacheConfigurations().get(
                    key.substring(0, key.lastIndexOf('-') - 1));
        }
        if (cc == null) {
            cc = cacheManager.getConfiguration().getDefaultCacheConfiguration();
        }
        if (cc == null) {
            cc = new CacheConfiguration();
        } else {
            cc = (CacheConfiguration)cc.clone();
        }
        cc.setName(key);
        return cc;
    }
View Full Code Here

    private EHCacheUtil() {
        //
    }
   
    public static CacheConfiguration getCacheConfiguration(String key, CacheManager cacheManager) {
        CacheConfiguration cc = cacheManager.getConfiguration().getCacheConfigurations().get(key);
        if (cc == null && key.contains("-")) {
            cc = cacheManager.getConfiguration().getCacheConfigurations().get(
                    key.substring(0, key.lastIndexOf('-') - 1));
        }
        if (cc == null) {
            cc = cacheManager.getConfiguration().getDefaultCacheConfiguration();
        }
        if (cc == null) {
            cc = new CacheConfiguration();
        } else {
            cc = (CacheConfiguration)cc.clone();
        }
        cc.setName(key);
        return cc;
    }
View Full Code Here

        } else {
            Configuration conf = ConfigurationFactory.parseConfiguration(configFileURL);
            cacheManager = CacheManager.create(conf);
        }
       
        CacheConfiguration cc = EHCacheUtil.getCacheConfiguration(key, cacheManager);
       
        Ehcache newCache = new Cache(cc);
        cache = cacheManager.addCacheIfAbsent(newCache);

        // Set the TimeToLive value from the CacheConfiguration
        ttl = cc.getTimeToLiveSeconds();
    }
View Full Code Here

    }
   
   
    public static CacheConfiguration getCacheConfiguration(String key,
                                                           CacheManager cacheManager) {
        CacheConfiguration cc = cacheManager.getConfiguration().getCacheConfigurations().get(key);
        if (cc == null && key.contains("-")) {
            cc = cacheManager.getConfiguration().getCacheConfigurations().get(
                    key.substring(0, key.lastIndexOf('-')));
        }
        if (cc == null) {
            cc = cacheManager.getConfiguration().getDefaultCacheConfiguration();
        }
        if (cc == null) {
            cc = new CacheConfiguration();
        } else {
            cc = (CacheConfiguration)cc.clone();
        }
        cc.setName(key);
        return cc;
    }
View Full Code Here

                 boolean clearOnFlush) {

        changeStatus(Status.STATUS_UNINITIALISED);


        configuration = new CacheConfiguration();
        configuration.setName(name);
        configuration.setMaxElementsInMemory(maxElementsInMemory);
        configuration.setMemoryStoreEvictionPolicyFromObject(memoryStoreEvictionPolicy);
        configuration.setOverflowToDisk(overflowToDisk);
        configuration.setEternal(eternal);
View Full Code Here

        status = Status.STATUS_UNINITIALISED;
        this.cache = cache;
        name = cache.getName();
        this.diskPath = diskPath;

        CacheConfiguration config = cache.getCacheConfiguration();
        expiryThreadInterval = config.getDiskExpiryThreadIntervalSeconds();
        persistent = config.isDiskPersistent();
        maxElementsOnDisk = config.getMaxElementsOnDisk();
        eternal = config.isEternal();
        diskSpoolBufferSizeBytes = cache.getCacheConfiguration().getDiskSpoolBufferSizeMB() * ONE_MEGABYTE;
        writeIndexFlag = new AtomicBoolean(false);
        writeIndexFlagLock = new Object();


View Full Code Here

      cacheFb.setCacheName("myCache1");
      cacheFb.afterPropertiesSet();
      cache = (Cache) cacheFb.getObject();
      Class<? extends Ehcache> objectType2 = cacheFb.getObjectType();
      assertSame(objectType, objectType2);
      CacheConfiguration config = cache.getCacheConfiguration();
      assertEquals("myCache1", cache.getName());
      if (useCacheManagerFb){
        assertEquals("myCache1.maxElements", 300, config.getMaxElementsInMemory());
      }
      else {
        assertEquals("myCache1.maxElements", 10000, config.getMaxElementsInMemory());
      }

      // Cache region is not defined. Should create one with default properties.
      cacheFb = new EhCacheFactoryBean();
      if (useCacheManagerFb) {
        cacheFb.setCacheManager(cacheManagerFb.getObject());
      }
      cacheFb.setCacheName("undefinedCache");
      cacheFb.afterPropertiesSet();
      cache = (Cache) cacheFb.getObject();
      config = cache.getCacheConfiguration();
      assertEquals("undefinedCache", cache.getName());
      assertTrue("default maxElements is correct", config.getMaxElementsInMemory() == 10000);
      assertFalse("default eternal is correct", config.isEternal());
      assertTrue("default timeToLive is correct", config.getTimeToLiveSeconds() == 120);
      assertTrue("default timeToIdle is correct", config.getTimeToIdleSeconds() == 120);
      assertTrue("default diskExpiryThreadIntervalSeconds is correct", config.getDiskExpiryThreadIntervalSeconds() == 120);

      // overriding the default properties
      cacheFb = new EhCacheFactoryBean();
      if (useCacheManagerFb) {
        cacheFb.setCacheManager(cacheManagerFb.getObject());
      }
      cacheFb.setBeanName("undefinedCache2");
      cacheFb.setMaxElementsInMemory(5);
      cacheFb.setTimeToLive(8);
      cacheFb.setTimeToIdle(7);
      cacheFb.setDiskExpiryThreadIntervalSeconds(10);
      cacheFb.afterPropertiesSet();
      cache = (Cache) cacheFb.getObject();
      config = cache.getCacheConfiguration();

      assertEquals("undefinedCache2", cache.getName());
      assertTrue("overridden maxElements is correct", config.getMaxElementsInMemory() == 5);
      assertTrue("default timeToLive is correct", config.getTimeToLiveSeconds() == 8);
      assertTrue("default timeToIdle is correct", config.getTimeToIdleSeconds() == 7);
      assertTrue("overridden diskExpiryThreadIntervalSeconds is correct", config.getDiskExpiryThreadIntervalSeconds() == 10);
    }
    finally {
      if (cacheManagerFbInitialized) {
        cacheManagerFb.destroy();
      }
View Full Code Here

  private EhCacheCache cache;

  @Before
  public void setUp() {
    cacheManager = new CacheManager(new Configuration().name("EhCacheCacheTests")
        .defaultCache(new CacheConfiguration("default", 100)));
    nativeCache = new net.sf.ehcache.Cache(new CacheConfiguration(CACHE_NAME, 100));
    cacheManager.addCache(nativeCache);

    cache = new EhCacheCache(nativeCache);
  }
View Full Code Here

TOP

Related Classes of net.sf.ehcache.config.CacheConfiguration

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.