Package net.sf.ehcache

Examples of net.sf.ehcache.Ehcache


        String cacheName = cacheName(key, metadata.getCacheGroups());

        // create empty cache for cache group here, as we have a factory to
        // create an object, and should never ever return null from this
        // method.
        Ehcache cache = cacheManager.addCacheIfAbsent(cacheName);
        Element result = cache.get(key);

        if (result != null) {
            return (List) result.getObjectValue();
        }

        // if no result in cache locking the key to write
        // and putting it to the cache
        cache.acquireWriteLockOnKey(key);
        try {

            // now that we locked the key, let's reread the cache again, in case
            // an object appeared there already
            result = cache.get(key);

            if (result != null) {
                return (List) result.getObjectValue();
            }

            // if not succeeded in reading again putting
            // object to the cache ourselves
            Object object = factory.createObject();
            if (!(object instanceof List)) {
                if (object == null) {
                    throw new CayenneRuntimeException("Null object created: " + metadata.getCacheKey());
                } else {
                    throw new CayenneRuntimeException("Invalid query result, expected List, got "
                            + object.getClass().getName());
                }
            }

            cache.put(new Element(key, object));

            return (List) object;

        } finally {
            cache.releaseWriteLockOnKey(key);
        }
    }
View Full Code Here


    public void put(QueryMetadata metadata, List results) {
        String key = metadata.getCacheKey();
        if (key != null) {
            String cacheName = cacheName(key, metadata.getCacheGroups());
            Ehcache cache = cacheManager.addCacheIfAbsent(cacheName);
            cache.put(new Element(key,results));
        }
    }
View Full Code Here

            }
        }  
    }

    public void removeGroup(String groupKey) {
        Ehcache cache = cacheManager.getEhcache(groupKey);
        if(cache != null) {
            cache.removeAll();
        }
    }
View Full Code Here

    public EHCacheReplayCache(String key, CacheManager cacheManager) {
        this.cacheManager = cacheManager;
       
        CacheConfiguration cc = EHCacheManagerHolder.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

        }

        if (LOG.isTraceEnabled()) {
            LOG.trace("Cache " + cacheName + " currently contains " + cacheManager.getCache(cacheName).getSize() + " elements");
        }
        Ehcache cache = cacheManager.getCache(cacheName);

        if (!cache.isKeyInCache(key)) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("No Key with name: " + key
                        + "presently exists in the cache. It is also possible that the key may have expired in the cache."
                        + " Replacement will not be performed until an appropriate key/value pair is added to (or) found in the cache.");
            }
View Full Code Here

      this.cacheName = this.beanName;
    }

    // Fetch cache region: If none with the given name exists,
    // create one on the fly.
    Ehcache rawCache;
    if (this.cacheManager.cacheExists(this.cacheName)) {
      if (logger.isDebugEnabled()) {
        logger.debug("Using existing EHCache cache region '" + this.cacheName + "'");
      }
      rawCache = this.cacheManager.getEhcache(this.cacheName);
    }
    else {
      if (logger.isDebugEnabled()) {
        logger.debug("Creating new EHCache cache region '" + this.cacheName + "'");
      }
      rawCache = createCache();
      this.cacheManager.addCache(rawCache);
    }

    if (this.cacheEventListeners != null) {
      for (CacheEventListener listener : this.cacheEventListeners) {
        rawCache.getCacheEventNotificationService().registerListener(listener);
      }
    }
    if (this.statisticsEnabled) {
      rawCache.setStatisticsEnabled(true);
    }
    if (this.sampledStatisticsEnabled) {
      rawCache.setSampledStatisticsEnabled(true);
    }
    if (this.disabled) {
      rawCache.setDisabled(true);
    }

    // Decorate cache if necessary.
    Ehcache decoratedCache = decorateCache(rawCache);
    if (decoratedCache != rawCache) {
      this.cacheManager.replaceCacheWithDecoratedCache(rawCache, decoratedCache);
    }
    this.cache = decoratedCache;
  }
View Full Code Here

  public Cache getCache(String name) {
    Cache cache = super.getCache(name);
    if (cache == null) {
      // check the EhCache cache again
      // (in case the cache was added at runtime)
      Ehcache ehcache = this.cacheManager.getEhcache(name);
      if (ehcache != null) {
        cache = new EhCacheCache(ehcache);
        addCache(cache);
      }
    }
View Full Code Here

      this.cacheName = this.beanName;
    }

    // Fetch cache region: If none with the given name exists,
    // create one on the fly.
    Ehcache rawCache;
    if (this.cacheManager.cacheExists(this.cacheName)) {
      if (logger.isDebugEnabled()) {
        logger.debug("Using existing EHCache cache region '" + this.cacheName + "'");
      }
      rawCache = this.cacheManager.getEhcache(this.cacheName);
    }
    else {
      if (logger.isDebugEnabled()) {
        logger.debug("Creating new EHCache cache region '" + this.cacheName + "'");
      }
      rawCache = createCache();
      this.cacheManager.addCache(rawCache);
    }

    // Decorate cache if necessary.
    Ehcache decoratedCache = decorateCache(rawCache);
    if (decoratedCache != rawCache) {
      this.cacheManager.replaceCacheWithDecoratedCache(rawCache, decoratedCache);
    }
    this.cache = decoratedCache;
  }
View Full Code Here

  public Cache getCache(String name) {
    Cache cache = super.getCache(name);
    if (cache == null) {
      // check the EhCache cache again
      // (in case the cache was added at runtime)
      Ehcache ehcache = this.cacheManager.getEhcache(name);
      if (ehcache != null) {
        cache = new EhCacheCache(ehcache);
        addCache(cache);
      }
    }
View Full Code Here

      this.cacheName = this.beanName;
    }

    // Fetch cache region: If none with the given name exists,
    // create one on the fly.
    Ehcache rawCache = null;
    if (this.cacheManager.cacheExists(this.cacheName)) {
      if (logger.isDebugEnabled()) {
        logger.debug("Using existing EHCache cache region '" + this.cacheName + "'");
      }
      rawCache = this.cacheManager.getEhcache(this.cacheName);
    }
    else {
      if (logger.isDebugEnabled()) {
        logger.debug("Creating new EHCache cache region '" + this.cacheName + "'");
      }
      rawCache = createCache();
      this.cacheManager.addCache(rawCache);
    }

    // Decorate cache if necessary.
    Ehcache decoratedCache = decorateCache(rawCache);
    if (decoratedCache != rawCache) {
      this.cacheManager.replaceCacheWithDecoratedCache(rawCache, decoratedCache);
    }
    this.cache = decoratedCache;
  }
View Full Code Here

TOP

Related Classes of net.sf.ehcache.Ehcache

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.