當前位置: 首頁>>代碼示例>>Java>>正文


Java Cache類代碼示例

本文整理匯總了Java中net.sf.ehcache.Cache的典型用法代碼示例。如果您正苦於以下問題:Java Cache類的具體用法?Java Cache怎麽用?Java Cache使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Cache類屬於net.sf.ehcache包,在下文中一共展示了Cache類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: cacheMonitor

import net.sf.ehcache.Cache; //導入依賴的package包/類
@Around("execution(* org.packt.aop.transaction.dao.impl.EmployeeDaoImpl.getEmployees(..))")
public Object cacheMonitor(ProceedingJoinPoint joinPoint) throws Throwable  {
   logger.info("executing " + joinPoint.getSignature().getName());
   Cache cache = cacheManager.getCache("employeesCache");
  
   logger.info("cache detected is  " + cache.getName());
   logger.info("begin caching.....");
   String key = joinPoint.getSignature().getName();
   logger.info(key);
   if(cache.get(key) == null){
	   logger.info("caching new Object.....");
	   Object result = joinPoint.proceed();
	   cache.put(new Element(key, result)); 	   
	   return result;
   }else{
	   logger.info("getting cached Object.....");
	   return cache.get(key).getObjectValue();
   }
}
 
開發者ID:PacktPublishing,項目名稱:Spring-5.0-Cookbook,代碼行數:20,代碼來源:CacheListenerAspect.java

示例2: createCachePool

import net.sf.ehcache.Cache; //導入依賴的package包/類
@Override
public CachePool createCachePool(String poolName, int cacheSize,
		int expiredSeconds) {
	CacheManager cacheManager = CacheManager.create();
	Cache enCache = cacheManager.getCache(poolName);
	if (enCache == null) {

		CacheConfiguration cacheConf = cacheManager.getConfiguration()
				.getDefaultCacheConfiguration().clone();
		cacheConf.setName(poolName);
		if (cacheConf.getMaxEntriesLocalHeap() != 0) {
			cacheConf.setMaxEntriesLocalHeap(cacheSize);
		} else {
			cacheConf.setMaxBytesLocalHeap(String.valueOf(cacheSize));
		}
		cacheConf.setTimeToIdleSeconds(expiredSeconds);
		Cache cache = new Cache(cacheConf);
		cacheManager.addCache(cache);
		return new EnchachePool(poolName,cache,cacheSize);
	} else {
		return new EnchachePool(poolName,enCache,cacheSize);
	}
}
 
開發者ID:huang-up,項目名稱:mycat-src-1.6.1-RELEASE,代碼行數:24,代碼來源:EnchachePooFactory.java

示例3: idleExample

import net.sf.ehcache.Cache; //導入依賴的package包/類
private void idleExample() throws InterruptedException {
    System.out.println("\nIdle example\n");
    Cache testCache = EhcacheHelper.createIdleCache(manager, "idleCache");
    testCache.put(new Element(0, "String: 0"));
    testCache.get(0);
    System.out.println("Hit count: " + testCache.getStatistics().cacheHitCount());
    System.out.println("Miss count: " + testCache.getStatistics().cacheMissCount());
    Thread.sleep(TimeUnit.SECONDS.toMillis(EhcacheHelper.IDLE_TIME_SEC) - 1);
    testCache.get(0);
    System.out.println("Hit count: " + testCache.getStatistics().cacheHitCount());
    System.out.println("Miss count: " + testCache.getStatistics().cacheMissCount());
    Thread.sleep(TimeUnit.SECONDS.toMillis(EhcacheHelper.IDLE_TIME_SEC) + 1);
    testCache.get(0);
    System.out.println("Hit count: " + testCache.getStatistics().cacheHitCount());
    System.out.println("Miss count: " + testCache.getStatistics().cacheMissCount());
}
 
開發者ID:vitaly-chibrikov,項目名稱:otus_java_2017_04,代碼行數:17,代碼來源:EhcaheMain.java

示例4: EhCacheWrapper

import net.sf.ehcache.Cache; //導入依賴的package包/類
/**
 * http://www.ehcache.org/documentation/2.8/code-samples.html#creating-caches-programmatically
 */
EhCacheWrapper(String cacheName) {
    AppConfiguration.Cache config = AppConfiguration.CONFIG.getCache();

    // Create a Cache specifying its configuration
    cache = new Cache(
            new CacheConfiguration(cacheName, config.getMaxSize())
                    .timeToLiveSeconds(TimeUnit.MINUTES.toSeconds(config.getLifeTime()))
                    .eternal(false)
                    .persistence(new PersistenceConfiguration().strategy(Strategy.NONE))
                    .memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.FIFO)
    );

    // The cache is not usable until it has been added
    manager.addCache(cache);
}
 
開發者ID:RWTH-i5-IDSG,項目名稱:xsharing-services-router,代碼行數:19,代碼來源:EhCacheWrapper.java

示例5: getCachedBuildRightSet

import net.sf.ehcache.Cache; //導入依賴的package包/類
private BuildRights getCachedBuildRightSet(final int activeBuildID, final int userID) {
    BuildRights buildRights = null;
    try {
      final Cache cache = getBuildRightSetCache(activeBuildID);
      if (cache == null) {
        return null;
      }
      final Element element = cache.get(new Integer(userID));
      if (element != null) {
        buildRights = (BuildRights) element.getValue();
      }
    } catch (Exception e) {
      if (log.isDebugEnabled()) {
        log.debug("e: " + e);
      }
    }
//    if (log.isDebugEnabled()) log.debug("cached rightSet for build ID " + activeBuildID + ", user ID " + userID + " : " + rightSet);
    return buildRights;
  }
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:20,代碼來源:SecurityManager.java

示例6: verifyEhCacheTicketRegistryWithClearPass

import net.sf.ehcache.Cache; //導入依賴的package包/類
@Test
public void verifyEhCacheTicketRegistryWithClearPass() {
    final Cache serviceTicketsCache = new Cache("serviceTicketsCache", 200, false, false, 100, 100);
    final Cache ticketGrantingTicketCache = new Cache("ticketGrantingTicketCache", 200, false, false, 100, 100);

    final CacheManager manager = new CacheManager(this.getClass().getClassLoader().getResourceAsStream("ehcacheClearPass.xml"));
    manager.addCache(serviceTicketsCache);
    manager.addCache(ticketGrantingTicketCache);

    final Map<String, String> map = new HashMap<>();

    final TicketRegistry ticketRegistry = new EhCacheTicketRegistry(serviceTicketsCache, ticketGrantingTicketCache);
    final TicketRegistryDecorator decorator = new TicketRegistryDecorator(ticketRegistry, map);
    assertNotNull(decorator);

    assertEquals(decorator.serviceTicketCount(), 0);
    assertEquals(decorator.sessionCount(), 0);

    manager.removalAll();
    manager.shutdown();

}
 
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:23,代碼來源:TicketRegistryDecoratorTests.java

示例7: EhCacheTicketRegistry

import net.sf.ehcache.Cache; //導入依賴的package包/類
/**
 * Instantiates a new EhCache ticket registry.
 *
 * @param ticketCache          the ticket cache
 * @param cipher               the cipher
 */
public EhCacheTicketRegistry(final Cache ticketCache, final CipherExecutor cipher) {
    this.ehcacheTicketsCache = ticketCache;
    setCipherExecutor(cipher);

    LOGGER.info("Setting up Ehcache Ticket Registry...");

    Assert.notNull(this.ehcacheTicketsCache, "Ehcache Tickets cache cannot nbe null");
    if (LOGGER.isDebugEnabled()) {
        final CacheConfiguration config = this.ehcacheTicketsCache.getCacheConfiguration();
        LOGGER.debug("TicketCache.maxEntriesLocalHeap=[{}]", config.getMaxEntriesLocalHeap());
        LOGGER.debug("TicketCache.maxEntriesLocalDisk=[{}]", config.getMaxEntriesLocalDisk());
        LOGGER.debug("TicketCache.maxEntriesInCache=[{}]", config.getMaxEntriesInCache());
        LOGGER.debug("TicketCache.persistenceConfiguration=[{}]", config.getPersistenceConfiguration().getStrategy());
        LOGGER.debug("TicketCache.synchronousWrites=[{}]", config.getPersistenceConfiguration().getSynchronousWrites());
        LOGGER.debug("TicketCache.timeToLive=[{}]", config.getTimeToLiveSeconds());
        LOGGER.debug("TicketCache.timeToIdle=[{}]", config.getTimeToIdleSeconds());
        LOGGER.debug("TicketCache.cacheManager=[{}]", this.ehcacheTicketsCache.getCacheManager().getName());
    }
}
 
開發者ID:mrluo735,項目名稱:cas-5.1.0,代碼行數:26,代碼來源:EhCacheTicketRegistry.java

示例8: crlDistributionPointRevocationChecker

import net.sf.ehcache.Cache; //導入依賴的package包/類
@Bean
public RevocationChecker crlDistributionPointRevocationChecker() {
    final X509Properties x509 = casProperties.getAuthn().getX509();
    final Cache cache = new Cache("CRL".concat(UUID.randomUUID().toString()),
            x509.getCacheMaxElementsInMemory(),
            x509.isCacheDiskOverflow(),
            x509.isCacheEternal(),
            x509.getCacheTimeToLiveSeconds(),
            x509.getCacheTimeToIdleSeconds());

    return new CRLDistributionPointRevocationChecker(
            x509.isCheckAll(),
            getRevocationPolicy(x509.getCrlUnavailablePolicy()),
            getRevocationPolicy(x509.getCrlExpiredPolicy()),
            cache,
            crlFetcher(),
            x509.isThrowOnFetchFailure());
}
 
開發者ID:mrluo735,項目名稱:cas-5.1.0,代碼行數:19,代碼來源:X509AuthenticationConfiguration.java

示例9: getOrAddCache

import net.sf.ehcache.Cache; //導入依賴的package包/類
public Cache getOrAddCache(String cacheName) {
    Cache cache = cacheManager.getCache(cacheName);
    if (cache == null) {
        synchronized (locker) {
            cache = cacheManager.getCache(cacheName);
            if (cache == null) {
                log.warn("Could not find cache config [" + cacheName + "], using default.");
                cacheManager.addCacheIfAbsent(cacheName);
                cache = cacheManager.getCache(cacheName);
                if (cacheEventListener != null) {
                    cache.getCacheEventNotificationService().registerListener(cacheEventListener);
                }
            }
        }
    }
    return cache;
}
 
開發者ID:yangfuhai,項目名稱:jboot,代碼行數:18,代碼來源:JbootEhcacheImpl.java

示例10: createLifeCache

import net.sf.ehcache.Cache; //導入依賴的package包/類
static Cache createLifeCache(CacheManager manager, String name) {
    CacheConfiguration configuration = new CacheConfiguration(name, MAX_ENTRIES);
    configuration.memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.FIFO)
            .timeToLiveSeconds(LIFE_TIME_SEC);

    Cache cache = new Cache(configuration);
    manager.addCache(cache);

    return cache;
}
 
開發者ID:vitaly-chibrikov,項目名稱:otus_java_2017_04,代碼行數:11,代碼來源:EhcacheHelper.java

示例11: createEternalCache

import net.sf.ehcache.Cache; //導入依賴的package包/類
static Cache createEternalCache(CacheManager manager, String name) {
    return createCache(
            manager,
            name,
            configuration -> configuration.memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.FIFO)
                    .eternal(true));

}
 
開發者ID:vitaly-chibrikov,項目名稱:otus_java_2017_06,代碼行數:9,代碼來源:EhcacheHelper.java

示例12: listCount

import net.sf.ehcache.Cache; //導入依賴的package包/類
public int listCount(Cnd c)
{
    Long num = 0L;
    Cache cache = CacheManager.getInstance().getCache(CACHE_NAME);
    if(cache.get(CACHE_COUNT_KEY) == null)
    {
        num = Long.valueOf(this.count(c));
        cache.put(new Element(CACHE_COUNT_KEY, num));
    }else{
        num = (Long)cache.get(CACHE_COUNT_KEY).getObjectValue();
    }
    return num.intValue();
}
 
開發者ID:lq10001,項目名稱:crm,代碼行數:14,代碼來源:EventtypeService.java

示例13: getCrlFromLdapWithNoCaching

import net.sf.ehcache.Cache; //導入依賴的package包/類
@Test
public void getCrlFromLdapWithNoCaching() throws Exception {
    for (int i = 0; i < 10; i++) {
        CacheManager.getInstance().removeAllCaches();
        final Cache cache = new Cache("crlCache-1", 100, false, false, 20, 10);
        CacheManager.getInstance().addCache(cache);
        final CRLDistributionPointRevocationChecker checker = new CRLDistributionPointRevocationChecker(cache, fetcher);
        checker.setThrowOnFetchFailure(true);
        checker.setUnavailableCRLPolicy(new AllowRevocationPolicy());
        final X509Certificate cert = CertUtils.readCertificate(new ClassPathResource("ldap-crl.crt"));
        checker.init();
        checker.check(cert);
    }
}
 
開發者ID:yuweijun,項目名稱:cas-server-4.2.1,代碼行數:15,代碼來源:PoolingLdaptiveResourceCRLFetcherTests.java

示例14: get

import net.sf.ehcache.Cache; //導入依賴的package包/類
public Data get(String dataID) {
	Cache tmpCache = cacheManager.getCache("tmp");
	if(tmpCache.get(dataID) != null)
		return (Data) tmpCache.get(dataID).getValue();
	else 
		return dataDao.get(dataID);
}
 
開發者ID:forweaver,項目名稱:forweaver2.0,代碼行數:8,代碼來源:DataService.java

示例15: getObjectID

import net.sf.ehcache.Cache; //導入依賴的package包/類
public String getObjectID(String dataName,Weaver weaver){
	Cache tmpNameCache = cacheManager.getCache("tmpName");
	dataName = dataName.replace(" ", "_");
	dataName = dataName.replace("?", "_");
	dataName = dataName.replace("#", "_");
	dataName = dataName.trim();

	Element element = tmpNameCache.get(weaver.getId()+"/"+dataName);

	if(element == null)
		return "";

	return (String)element.getValue();
}
 
開發者ID:forweaver,項目名稱:forweaver2.0,代碼行數:15,代碼來源:DataService.java


注:本文中的net.sf.ehcache.Cache類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。