Package org.springframework.cache.ehcache

Examples of org.springframework.cache.ehcache.EhCacheCacheManager


    private final Logger logger = LoggerFactory.getLogger(getClass());

    @Override
    protected void mergeTemplate(Template template, Context context, HttpServletResponse response) throws Exception {
        try {
            EhCacheCacheManager ehCacheCacheManager = (EhCacheCacheManager) getAttributesMap().get("ehCacheCacheManager");
            CacheManager cacheManager = ehCacheCacheManager.getCacheManager();
            String cacheName = (String) getAttributesMap().get("cacheName");
            Cache cache = cacheManager != null && StringUtils.isNotEmpty(cacheName) ? cacheManager.getCache(cacheName) : null;

            HttpServletRequest request = ((ChainedContext) context).getRequest();
            boolean isGet = StringUtils.equals("GET", request.getMethod());
View Full Code Here


                cache.getCacheConfiguration().setTimeToLiveSeconds(env.getProperty("cache.timeToLiveSeconds", Long.class, 3600L));
                net.sf.ehcache.Ehcache decoratedCache = InstrumentedEhcache.instrument(metricRegistry, cache);
                cacheManager.replaceCacheWithDecoratedCache(cache, decoratedCache);
            }
        }
        EhCacheCacheManager ehCacheManager = new EhCacheCacheManager();
        ehCacheManager.setCacheManager(cacheManager);
        return ehCacheManager;
    }
View Full Code Here

        //创建底层Cache
        net.sf.ehcache.CacheManager ehcacheManager
                = new net.sf.ehcache.CacheManager(new ClassPathResource("ehcache.xml").getInputStream());

        //创建Spring的CacheManager
        EhCacheCacheManager cacheCacheManager = new EhCacheCacheManager();
        //设置底层的CacheManager
        cacheCacheManager.setCacheManager(ehcacheManager);

        Long id = 1L;
        User user = new User(id, "zhang", "zhang@gmail.com");

        //根据缓存名字获取Cache
        Cache cache = cacheCacheManager.getCache("user");
        //往缓存写数据
        cache.put(id, user);
        //从缓存读数据
        Assert.assertNotNull(cache.get(id, User.class));
    }
View Full Code Here

        try {
            net.sf.ehcache.CacheManager ehcacheCacheManager
                    = new net.sf.ehcache.CacheManager(new ClassPathResource("ehcache.xml").getInputStream());

            EhCacheCacheManager cacheCacheManager = new EhCacheCacheManager(ehcacheCacheManager);
            return cacheCacheManager;
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
View Full Code Here

    }

    @Bean
    @Override
    public CacheManager cacheManager() {
        return new EhCacheCacheManager(ehCacheManager());
    }
View Full Code Here

public class MockDynamicCacheConfig extends DynamicCacheConfig {

  @SuppressWarnings("rawtypes")
  @Override
  public EhCacheCacheManager dynamicCacheManager() {
    EhCacheCacheManager cacheManager = new EhCacheCacheManager();
    Configuration cacheManagerConfig;
    InputStream inputStream = null;
    try {

      CoreLogger.LOGGER.info("In cluster mode.");
      inputStream = new ClassPathResource("ehcache-dist.xml").getInputStream();
      cacheManagerConfig = ConfigurationFactory.parseConfiguration(inputStream);
      FactoryConfiguration peerProviderConfig = new FactoryConfiguration();
      peerProviderConfig.setClass(RMICacheManagerPeerProviderFactory.class.getName());
      List<String> replicatedCacheNames = getReplicatedCacheNames(cacheManagerConfig);
      Pair<NetworkUtils.IPPortPair, String> properties = createManualDiscoveryCacheProperties(replicatedCacheNames);
      NetworkUtils.IPPortPair currentListener = properties.getFirst();
      String peerProperty = properties.getSecond();
      peerProviderConfig.setProperties(peerProperty);
      cacheManagerConfig.addCacheManagerPeerProviderFactory(peerProviderConfig);
      System.setProperty("java.rmi.server.hostname", currentListener.getFormattedIP());
      FactoryConfiguration peerListenerConfig = new FactoryConfiguration();
      peerListenerConfig.setClass(RMICacheManagerPeerListenerFactory.class.getName());
      String peerListenerProperty = String.format("hostName=%s, port=%d, socketTimeoutMillis=1000",
          currentListener.getFormattedIP(), currentListener.getPort());
      peerListenerConfig.setProperties(peerListenerProperty);
      cacheManagerConfig.addCacheManagerPeerListenerFactory(peerListenerConfig);
      CoreLogger.LOGGER.info("clusterURLs:{}", peerListenerProperty);
      cacheManagerConfig.setName("TestCluster");
      CacheManager mgr = CacheManager.create(cacheManagerConfig);
      cacheManager.setCacheManager(mgr);
    } catch (IOException e) {
      CoreLogger.LOGGER.error("Error while setting up cache", e);
    } finally {
      IOUtils.closeQuietly(inputStream);
    }
View Full Code Here

   * @return EhCacheCacheManager bean
   */
  @SuppressWarnings("rawtypes")
  @Bean(name = "cacheManager")
  public EhCacheCacheManager dynamicCacheManager() {
    EhCacheCacheManager cacheManager = new EhCacheCacheManager();
    Configuration cacheManagerConfig;
    InputStream inputStream = null;
    try {
      if (!isClustered()) {
        inputStream = new ClassPathResource("ehcache.xml").getInputStream();
        cacheManagerConfig = ConfigurationFactory.parseConfiguration(inputStream);
      } else {
        CoreLogger.LOGGER.info("In cluster mode.");
        inputStream = new ClassPathResource("ehcache-dist.xml").getInputStream();
        cacheManagerConfig = ConfigurationFactory.parseConfiguration(inputStream);
        Pair<FactoryConfiguration, NetworkUtils.IPPortPair> result =
            createRMICacheManagerPeerProviderFactory(cacheManagerConfig);
        cacheManagerConfig.addCacheManagerPeerProviderFactory(result.getFirst());
        cacheManagerConfig.addCacheManagerPeerListenerFactory(
            createPearListenerFactory(result.getSecond().getIP(), result.getSecond().getPort()));
      }
      cacheManagerConfig.setName(getCacheName());
      CacheManager mgr = CacheManager.create(cacheManagerConfig);
      cacheManager.setCacheManager(mgr);

    } catch (IOException e) {
      CoreLogger.LOGGER.error("Error while setting up cache", e);
    } finally {
      IOUtils.closeQuietly(inputStream);
View Full Code Here

            Cache groupUserCache = cacheManager.getCache("group-user-cache");
            Ehcache decoratedGroupUserCache = InstrumentedEhcache.instrument(groupUserCache);
            cacheManager.replaceCacheWithDecoratedCache(groupUserCache, decoratedGroupUserCache);
        }
        EhCacheCacheManager ehCacheManager = new EhCacheCacheManager();
        ehCacheManager.setCacheManager(cacheManager);
        return ehCacheManager;
    }
View Full Code Here

TOP

Related Classes of org.springframework.cache.ehcache.EhCacheCacheManager

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.