Package net.sf.ehcache

Examples of net.sf.ehcache.CacheManager


  public ResourceFactoryCache createFactoryCache()
  {
    try
    {
      final CacheManager manager = getCacheManager();
      synchronized(manager)
      {
        if (manager.cacheExists(FACTORY_CACHE_NAME) == false)
        {
          final Cache libloaderCache = new Cache(FACTORY_CACHE_NAME,   // cache name
                                                 500,         // maxElementsInMemory
                                                 false,       // overflowToDisk
                                                 false,       // eternal
                                                 600,         // timeToLiveSeconds
                                                 600,         // timeToIdleSeconds
                                                 false,       // diskPersistent
                                                 120);        // diskExpiryThreadIntervalSeconds
          manager.addCache(libloaderCache);
          return new EHResourceFactoryCache(libloaderCache);
        }
        else
        {
          return new EHResourceFactoryCache(manager.getCache(FACTORY_CACHE_NAME));
        }
      }
    }
    catch (CacheException e)
    {
View Full Code Here


    this.directory = directory;
    this.reporter = reporter;
    this.ioFileBufferSize = bufSize;
    String diskCacheDir = new File(conf.get("hadoop.tmp.dir"), "fsdir-cache").toString();
    LogManager.getLogger(FsDirectory.class).setLevel(Level.WARN);
    CacheManager mgr = CacheManager.create();
    synchronized(mgr) {
      cache = mgr.getCache("dfsin");
      if (cache == null) {
        cache = new Cache("dfsin", 2000, MemoryStoreEvictionPolicy.LFU,
                true, diskCacheDir, false, 1800, 600, false, 300, null);
        mgr.addCache(cache);
        cache = mgr.getCache("dfsin");
        LOG.info("Created cache: " + cache.toString());
      }
    }
    if (create) {
      create();
View Full Code Here

  protected CacheManager getCacheManager() {
    if(cacheManager==null) {
      String cacheConfigLocation = getFilterConfig()
          .getInitParameter(CACHE_CONFIG_LOCATION);
      URL url = getClass().getResource(cacheConfigLocation);
      cacheManager = new CacheManager(url);
    }
    return cacheManager;
  }
View Full Code Here

 
  protected CacheManager getCacheManager() {
    if(cacheManager==null) {
      Resource resource = resourceLoader.getResource(cacheConfigLocation);
      try {
        cacheManager = new CacheManager(resource.getURL());
      } catch (CacheException e) {
        e.printStackTrace();
      } catch (IOException e) {
        e.printStackTrace();
      }
View Full Code Here

    @DB(txn=false)
    protected void createCache(final Map<String, ? extends Object> params) {
        final String value = (String)params.get("cache.size");

        if (value != null) {
            final CacheManager cm = CacheManager.create();
            final int maxElements = NumbersUtil.parseInt(value, 0);
            final int live = NumbersUtil.parseInt((String)params.get("cache.time.to.live"), 300);
            final int idle = NumbersUtil.parseInt((String)params.get("cache.time.to.idle"), 300);
            _cache = new Cache(getName(), maxElements, false, live == -1, live == -1 ? Integer.MAX_VALUE : live, idle);
            cm.addCache(_cache);
            s_logger.info("Cache created: " + _cache.toString());
        } else {
            _cache = null;
        }
    }
View Full Code Here

            int maxElements = 10000;
            String cachesize = _configDao.getValue(Config.ApiLimitCacheSize.key());
            if ( cachesize != null ){
                maxElements = Integer.parseInt(cachesize);
            }
            CacheManager cm = CacheManager.create();
            Cache cache = new Cache("api-limit-cache", maxElements, false, false, timeToLive, timeToLive);
            cm.addCache(cache);
            s_logger.info("Limit Cache created with timeToLive=" + timeToLive + ", maxAllowed=" + maxAllowed + ", maxElements=" + maxElements );
            cacheStore.setCache(cache);
            _store = cacheStore;

        }
View Full Code Here

        cc.setName(key);
        return cc;
    }
   
    public static CacheManager getCacheManager(Bus bus, URL configFileURL) {
        CacheManager cacheManager = null;
       
        String globalCacheManagerName = getGlobalCacheManagerName(bus);
        if (globalCacheManagerName != null) {
            cacheManager = CacheManager.getCacheManager(globalCacheManagerName);
        }
       
        // notice for a global cache manager, we skip the count stuff which
        // means the release cache manager method below is a no op, as the
        // COUNT will not have been initialised.
        if (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());
            }
        }
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

            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

       
    }
   
    @Test
    public void testCacheNames() {
        CacheManager cacheManager =
            EHCacheManagerHolder.getCacheManager("testCache2",
                                                 EHCacheManagerHolder.class.getResource("/test-ehcache2.xml"));
       
        String key = "org.apache.wss4j.TokenStore";
        CacheConfiguration cacheConfig =
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.