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


Java Ehcache.get方法代码示例

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


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

示例1: 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

示例2: 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

示例3: updateHits

import net.sf.ehcache.Ehcache; //导入方法依赖的package包/类
/**
 * 更新点击数
 */
@SuppressWarnings("unchecked")
private void updateHits() {
	Ehcache cache = cacheManager.getEhcache(Article.HITS_CACHE_NAME);
	List<Long> ids = cache.getKeys();
	for (Long id : ids) {
		Article article = articleDao.find(id);
		if (article != null) {
			Element element = cache.get(id);
			long hits = (Long) element.getObjectValue();
			article.setHits(hits);
			articleDao.merge(article);
		}
	}
}
 
开发者ID:justinbaby,项目名称:my-paper,代码行数:18,代码来源:ArticleServiceImpl.java

示例4: updateHits

import net.sf.ehcache.Ehcache; //导入方法依赖的package包/类
/**
 * 更新点击数
 */
@SuppressWarnings("unchecked")
private void updateHits() {
	Ehcache cache = cacheManager.getEhcache(Product.HITS_CACHE_NAME);
	List<Long> ids = cache.getKeys();
	for (Long id : ids) {
		Product product = productDao.find(id);
		if (product != null) {
			productDao.lock(product, LockModeType.PESSIMISTIC_WRITE);
			Element element = cache.get(id);
			long hits = (Long) element.getObjectValue();
			long increment = hits - product.getHits();
			Calendar nowCalendar = Calendar.getInstance();
			Calendar weekHitsCalendar = DateUtils.toCalendar(product.getWeekHitsDate());
			Calendar monthHitsCalendar = DateUtils.toCalendar(product.getMonthHitsDate());
			if (nowCalendar.get(Calendar.YEAR) != weekHitsCalendar.get(Calendar.YEAR) || nowCalendar.get(Calendar.WEEK_OF_YEAR) > weekHitsCalendar.get(Calendar.WEEK_OF_YEAR)) {
				product.setWeekHits(increment);
			} else {
				product.setWeekHits(product.getWeekHits() + increment);
			}
			if (nowCalendar.get(Calendar.YEAR) != monthHitsCalendar.get(Calendar.YEAR) || nowCalendar.get(Calendar.MONTH) > monthHitsCalendar.get(Calendar.MONTH)) {
				product.setMonthHits(increment);
			} else {
				product.setMonthHits(product.getMonthHits() + increment);
			}
			product.setHits(hits);
			product.setWeekHitsDate(new Date());
			product.setMonthHitsDate(new Date());
			productDao.merge(product);
		}
	}
}
 
开发者ID:justinbaby,项目名称:my-paper,代码行数:35,代码来源:ProductServiceImpl.java


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