<dependency> <groupId>net.sf.ehcache</groupId> <artifactId>ehcache-core</artifactId> <version>2.6.11</version> </dependency>
spring: cache: jcache: config: classpath:ehcache.xml
<cache name="dayHits" maxEntriesLocalHeap="500" eternal="true" overflowToDisk="true"> </cache>
public Integer cacheCount(Long articleId){
Content content = contentRepository.findOne(articleId);
Ehcache cache = cacheManager.getEhcache("dayHits");
Element element = cache.get(articleId+"_count");
Integer count = 0;
if(element!=null){
count = (Integer) element.getValue();
}else{
count = content.getHits()== null?0:content.getHits();
}
count++;
cache.put(new Element(articleId+"_count",count));
cache.put(new Element(articleId+"_dayHitsDate",SystemUtils.getNowDate()));
Long time = System.currentTimeMillis();
if(time > (viewArticleTime+ 300000)){
viewArticleTime = time;
content.setHits(count);
contentRepository.save(content);
cache.removeAll();
}
return count;
}
@RequestMapping(value = "article/{id}",method = RequestMethod. GET)
public String detail(@PathVariable Long id,ModelMap map){
Integer hits = cacheCount(id);
}
private static CacheManager cacheManager = CacheManager.newInstance(); private static Long viewArticleTime = System.currentTimeMillis();
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有