当前位置: 首页>>代码示例>>Java>>正文


Java Ehcache类代码示例

本文整理汇总了Java中net.sf.ehcache.Ehcache的典型用法代码示例。如果您正苦于以下问题:Java Ehcache类的具体用法?Java Ehcache怎么用?Java Ehcache使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Ehcache类属于net.sf.ehcache包,在下文中一共展示了Ehcache类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getObjectType

import net.sf.ehcache.Ehcache; //导入依赖的package包/类
/**
 * Predict the particular {@code Ehcache} implementation that will be returned from
 * {@link #getObject()} based on logic in {@link #createCache()} and
 * {@link #decorateCache(Ehcache)} as orchestrated by {@link #afterPropertiesSet()}.
 */
@Override
public Class<? extends Ehcache> getObjectType() {
	if (this.cache != null) {
		return this.cache.getClass();
	}
	if (this.cacheEntryFactory != null) {
		if (this.cacheEntryFactory instanceof UpdatingCacheEntryFactory) {
			return UpdatingSelfPopulatingCache.class;
		}
		else {
			return SelfPopulatingCache.class;
		}
	}
	if (this.blocking) {
		return BlockingCache.class;
	}
	return Cache.class;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:24,代码来源:EhCacheFactoryBean.java

示例2: getAllSessions

import net.sf.ehcache.Ehcache; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
   public Collection<Session> getAllSessions() {
   	Collection<Session> sessions = new ArrayList<Session>(0);
	try {
		Object object = cacheManager.getCache(this.activeSessionsCacheName).getNativeCache();
		if(object instanceof Ehcache)
		{
			Ehcache ehcache = (Ehcache)object;
			List<Serializable> keys = ehcache.getKeysWithExpiryCheck();
			if (!CollectionUtils.isEmpty(keys)) {
				for (Serializable key : keys) {
					sessions.add(getSession(key));
				}
			}
		}
	} catch (Exception e) {
		logger.error("获取全部session异常", e);
	}
      
       return sessions;
   }
 
开发者ID:wjggwm,项目名称:webside,代码行数:23,代码来源:EhCacheShiroSessionRepository.java

示例3: lookup

import net.sf.ehcache.Ehcache; //导入依赖的package包/类
/**
 * Use the Ehcache provided search API to perform criteria queries on defined search attributes.
 * NOTE: Requires search attributes to be previously defined in Ehcache config!
 * DEPRECATED because at observed large cache quantities the search noticeably slows down the system
 * @param params the search parameters as key/value pairs
 * @return the first found cache hit
 */
@Deprecated
@SuppressWarnings("unchecked")
public VALUE lookup(Map<String, String> params) {
    Query q = cache.createQuery();

    for (Map.Entry<String, String> param : params.entrySet()) {
        Attribute<String> theAttribute = ((Ehcache) cache).getSearchAttribute(param.getKey());
        q.addCriteria(theAttribute.eq(param.getValue()));
    }

    q.includeKeys().includeValues();
    Results results = q.execute();

    if (results == null || results.size() == 0) {
        return null;
    }

    if (results.size() > 1) {
        log.warn("There are multiple entries registered for params: {}", params.toString());
    }

    return (VALUE) results.all().get(0).getValue();
}
 
开发者ID:RWTH-i5-IDSG,项目名称:xsharing-services-router,代码行数:31,代码来源:EhCacheWrapper.java

示例4: testEhCacheFactoryBeanWithBlockingCache

import net.sf.ehcache.Ehcache; //导入依赖的package包/类
@Test
public void testEhCacheFactoryBeanWithBlockingCache() throws Exception {
	EhCacheManagerFactoryBean cacheManagerFb = new EhCacheManagerFactoryBean();
	cacheManagerFb.afterPropertiesSet();
	try {
		CacheManager cm = cacheManagerFb.getObject();
		EhCacheFactoryBean cacheFb = new EhCacheFactoryBean();
		cacheFb.setCacheManager(cm);
		cacheFb.setCacheName("myCache1");
		cacheFb.setBlocking(true);
		assertEquals(cacheFb.getObjectType(), BlockingCache.class);
		cacheFb.afterPropertiesSet();
		Ehcache myCache1 = cm.getEhcache("myCache1");
		assertTrue(myCache1 instanceof BlockingCache);
	}
	finally {
		cacheManagerFb.destroy();
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:20,代码来源:EhCacheSupportTests.java

示例5: testEhCacheFactoryBeanWithSelfPopulatingCache

import net.sf.ehcache.Ehcache; //导入依赖的package包/类
@Test
public void testEhCacheFactoryBeanWithSelfPopulatingCache() throws Exception {
	EhCacheManagerFactoryBean cacheManagerFb = new EhCacheManagerFactoryBean();
	cacheManagerFb.afterPropertiesSet();
	try {
		CacheManager cm = cacheManagerFb.getObject();
		EhCacheFactoryBean cacheFb = new EhCacheFactoryBean();
		cacheFb.setCacheManager(cm);
		cacheFb.setCacheName("myCache1");
		cacheFb.setCacheEntryFactory(new CacheEntryFactory() {
			@Override
			public Object createEntry(Object key) throws Exception {
				return key;
			}
		});
		assertEquals(cacheFb.getObjectType(), SelfPopulatingCache.class);
		cacheFb.afterPropertiesSet();
		Ehcache myCache1 = cm.getEhcache("myCache1");
		assertTrue(myCache1 instanceof SelfPopulatingCache);
		assertEquals("myKey1", myCache1.get("myKey1").getValue());
	}
	finally {
		cacheManagerFb.destroy();
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:26,代码来源:EhCacheSupportTests.java

示例6: viewHits

import net.sf.ehcache.Ehcache; //导入依赖的package包/类
public long viewHits(Long id) {
	Ehcache cache = cacheManager.getEhcache(Article.HITS_CACHE_NAME);
	Element element = cache.get(id);
	Long hits;
	if (element != null) {
		hits = (Long) element.getObjectValue();
	} else {
		Article article = articleDao.find(id);
		if (article == null) {
			return 0L;
		}
		hits = article.getHits();
	}
	hits++;
	cache.put(new Element(id, hits));
	long time = System.currentTimeMillis();
	if (time > viewHitsTime + Article.HITS_CACHE_INTERVAL) {
		viewHitsTime = time;
		updateHits();
		cache.removeAll();
	}
	return hits;
}
 
开发者ID:justinbaby,项目名称:my-paper,代码行数:24,代码来源:ArticleServiceImpl.java

示例7: viewHits

import net.sf.ehcache.Ehcache; //导入依赖的package包/类
public long viewHits(Long id) {
	Ehcache cache = cacheManager.getEhcache(Product.HITS_CACHE_NAME);
	Element element = cache.get(id);
	Long hits;
	if (element != null) {
		hits = (Long) element.getObjectValue();
	} else {
		Product product = productDao.find(id);
		if (product == null) {
			return 0L;
		}
		hits = product.getHits();
	}
	hits++;
	cache.put(new Element(id, hits));
	long time = System.currentTimeMillis();
	if (time > viewHitsTime + Product.HITS_CACHE_INTERVAL) {
		viewHitsTime = time;
		updateHits();
		cache.removeAll();
	}
	return hits;
}
 
开发者ID:justinbaby,项目名称:my-paper,代码行数:24,代码来源:ProductServiceImpl.java

示例8: isValid

import net.sf.ehcache.Ehcache; //导入依赖的package包/类
public boolean isValid(CacheManager cacheManager, String cacheName, String key) {
    LOG.trace("Cache Name: {}", cacheName);

    if (!cacheManager.cacheExists(cacheName)) {
        LOG.debug("No existing Cache found with name: {}"
                + ". Please ensure a cache is first instantiated using a Cache Consumer or Cache Producer."
                + " Replacement will not be performed since the cache {} does not presently exist", cacheName, cacheName);
        return false;
    }

    LOG.debug("Found an existing cache: {}", cacheName);

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

    if (!cache.isKeyInCache(key)) {
        LOG.debug("No Key with name: {} 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.", key);
        return false;
    }

    return true;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:26,代码来源:CacheValidate.java

示例9: dispatchExchange

import net.sf.ehcache.Ehcache; //导入依赖的package包/类
private void dispatchExchange(Ehcache cache, Element element, String operation) {
    Exchange exchange;
    LOG.debug("Consumer Dispatching the Exchange containing the Element {} in cache {}", element, cache.getName());
    
    if (element == null) {
        exchange = cacheConsumer.getEndpoint().createCacheExchange(operation, "", "");
    } else {
        exchange = cacheConsumer.getEndpoint().createCacheExchange(operation, (String) element.getObjectKey(), element.getObjectValue());
    }
    try {
        cacheConsumer.getProcessor().process(exchange);
    } catch (Exception e) {
        throw new CacheException("Error in consumer while dispatching exchange containing key "
            + (element != null ? element.getObjectKey() : null) + " for further processing", e);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:17,代码来源:CacheEventListener.java

示例10: size

import net.sf.ehcache.Ehcache; //导入依赖的package包/类
@Override
public int size() {
	if (springCache.getNativeCache() instanceof Ehcache) {
		Ehcache ehcache = (Ehcache) springCache.getNativeCache();
		return ehcache.getSize();
	}
	throw new UnsupportedOperationException(
			"invoke spring cache abstract size method not supported");
}
 
开发者ID:jiangzongyao,项目名称:kettle_support_kettle8.0,代码行数:10,代码来源:SpringCacheManager.java

示例11: keys

import net.sf.ehcache.Ehcache; //导入依赖的package包/类
@Override
public Set keys() {
	if (springCache.getNativeCache() instanceof Ehcache) {
		Ehcache ehcache = (Ehcache) springCache.getNativeCache();
		return new HashSet(ehcache.getKeys());
	}
	throw new UnsupportedOperationException(
			"invoke spring cache abstract keys method not supported");
}
 
开发者ID:jiangzongyao,项目名称:kettle_support_kettle8.0,代码行数:10,代码来源:SpringCacheManager.java

示例12: getEhcache

import net.sf.ehcache.Ehcache; //导入依赖的package包/类
/**
 * 创建本地缓存
 */
private Ehcache getEhcache(final String name) {
    Future<Ehcache> future = this.ehcaches.get(name);
    if (future == null) {
        Callable<Ehcache> callable = new Callable<Ehcache>() {
            @Override
            public Ehcache call() throws Exception {
                Ehcache cache = cacheManager.getEhcache(name);
                if (cache == null) {
                    cacheManager.addCache(name);
                    cache = cacheManager.getEhcache(name);
                }
                return cache;
            }
        };
        FutureTask<Ehcache> task = new FutureTask<>(callable);
        future = this.ehcaches.putIfAbsent(name, task);
        if (future == null) {
            future = task;
            task.run();
        }
    }
    try {
        return future.get();
    } catch (Exception e) {
        this.ehcaches.remove(name);
        throw new CacheException(e);
    }
}
 
开发者ID:yrain,项目名称:smart-cache,代码行数:32,代码来源:CacheTemplate.java

示例13: size

import net.sf.ehcache.Ehcache; //导入依赖的package包/类
@Override
public int size() {
    if(springCache.getNativeCache() instanceof Ehcache) {
        Ehcache ehcache = (Ehcache) springCache.getNativeCache();
        return ehcache.getSize();
    }
    throw new UnsupportedOperationException("invoke spring cache abstract size method not supported");
}
 
开发者ID:liaojiacan,项目名称:zkAdmin,代码行数:9,代码来源:SpringCacheManagerWrapper.java

示例14: keys

import net.sf.ehcache.Ehcache; //导入依赖的package包/类
@Override
public Set keys() {
    if(springCache.getNativeCache() instanceof Ehcache) {
        Ehcache ehcache = (Ehcache) springCache.getNativeCache();
        return new HashSet(ehcache.getKeys());
    }
    throw new UnsupportedOperationException("invoke spring cache abstract keys method not supported");
}
 
开发者ID:liaojiacan,项目名称:zkAdmin,代码行数:9,代码来源:SpringCacheManagerWrapper.java

示例15: onSetUpInTransaction

import net.sf.ehcache.Ehcache; //导入依赖的package包/类
protected void onSetUpInTransaction() {

        // make a cache
        CacheManager cacheManager = CacheManager.create();
        if (! cacheManager.cacheExists("ehcache.sakai.kaltura.entries")) {
            cacheManager.addCache("ehcache.sakai.kaltura.entries");
        }
        Ehcache entriesCache = cacheManager.getCache("ehcache.sakai.kaltura.entries");

        // create and setup the object to be tested
        external = new ExternalLogicStub();
        service = new KalturaAPIService();
        service.setExternal(external);
        service.setEntriesCache(entriesCache);
        service.setOffline(true); // for testing we do not try to fetch real data

        // run the init
        external.currentUserId = FakeDataPreload.ADMIN_USER_ID; // DEFAULT ADMIN
        // UNICON settings for testing
        external.config.put("kaltura.partnerid", 166762);
        external.config.put("kaltura.adminsecret", "26d08a0ba54c911492bbc7599028295f");
        external.config.put("kaltura.secret", "6e4755b613a38b19e4cfb5d7405ed170");

        service.testWSInit(); // SPECIAL INIT

        service.getKalturaClient();
    }
 
开发者ID:ITYug,项目名称:kaltura-ce-sakai-extension,代码行数:28,代码来源:KalturaTestWebservices.java


注:本文中的net.sf.ehcache.Ehcache类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。