本文整理汇总了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;
}
示例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;
}
示例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);
}
}
}
示例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);
}
}
}