當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。