Package net.sf.ehcache

Examples of net.sf.ehcache.Ehcache


        if (key == null) {
            return null;
        }

        String cacheName = cacheName(key, metadata.getCacheGroups());
        Ehcache cache = cacheManager.getCache(cacheName);

        if (cache == null) {
            return null;
        }

        Element result = cache.get(key);
        return result != null ? (List) result.getObjectValue() : null;
    }
View Full Code Here


        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

    @SuppressWarnings("rawtypes")
    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

        cacheFactory.afterPropertiesSet();
      }catch(Exception e){
        //TODO: do something
        e.printStackTrace();
      }
      Ehcache settingCache = cacheFactory.getObject();
     
      settingService.setSettingCache(settingCache);
    }
   
    return settingService;
View Full Code Here

  }

  @Override
  public Cache create(final String id) {
    this.manager.addCache(id);
    Ehcache cache = this.manager.getEhcache(id);
    return new EHCacheImpl(cache);
  }
View Full Code Here

    return new EHCacheImpl(cache);
  }

  @Override
  public Cache get(final String id) {
    Ehcache cache = this.manager.getEhcache(id);
    return new EHCacheImpl(cache);
  }
View Full Code Here

        }
        cacheManager = EHCacheManagerHolder.getCacheManager(bus, configFileURL);
       
        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

        entityMock.expects(once()).method("getId").withNoArguments().will(returnValue(entityOid));
        cacheMock.expects(once()).method("put").with(eq(element));
        cacheMock.expects(atLeastOnce()).method("get").with(eq(WINDOW_ID)).will(returnValue(element));
       
       
        Ehcache cache = (Ehcache) cacheMock.proxy();       
        PortletWindowCache windowCache = new EhPortletWindowCache(cache);     
        windowCache.putPortletWindow(window);
       
        assertNotNull(windowCache.getPortletWindow(WINDOW_ID));
        assertEquals(windowCache.getPortletWindow(WINDOW_ID), window);
View Full Code Here

        cacheMock.expects(once()).method("get").with(eq(WINDOW_ID)).will(returnValue(element));
        windowMock.expects(once()).method("getId").withNoArguments().will(returnValue(oid));
        windowMock.expects(once()).method("getPortletEntity").withNoArguments().will(returnValue(entityMock.proxy()));
        entityMock.expects(once()).method("getId").withNoArguments().will(returnValue(entityOid));
       
        Ehcache cache = (Ehcache) cacheMock.proxy();       
        PortletWindowCache windowCache = new EhPortletWindowCache(cache)
        windowCache.putPortletWindow(window);
       
        PortletWindow fromCache = windowCache.getPortletWindowByEntityId(ENTITY_ID);
        assertNotNull(fromCache);
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.