本文整理匯總了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();
}
}
示例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);
}
}
示例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());
}
示例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);
}
示例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;
}
示例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();
}
示例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());
}
}
示例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());
}
示例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;
}
示例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;
}
示例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));
}
示例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();
}
示例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);
}
}
示例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);
}
示例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();
}