设为首页 加入收藏

TOP

Spring整合ehcache 注解实现查询缓存,并实现实时缓存更新或删除(一)
2015-11-12 23:05:53 来源: 作者: 【 】 浏览:27
Tags:Spring 整合 ehcache 注解 实现 查询 实时 更新 删除

注:引入jar


? ? ? ?
? ? ? ?
? ? ? ? ? ? net.sf.ehcache
? ? ? ? ? ? ehcache
? ? ? ? ? ? 2.8.3
? ? ? ?


第一步:首先配置ehcache.xml



? ? ? ? xsi:noNamespaceSchemaLocation="ehcache.xsd"
? ? ? ? updateCheck="true" monitoring="autodetect"
? ? ? ? dynamicConfig="true">
? ?
? ? ?
? ? ? ? ? ? ? maxEntriesLocalHeap="10000"
? ? ? ? ? ? eternal="false"
? ? ? ? ? ? overflowToDisk="false"
? ? ? ? ? ? timeToIdleSeconds="120"
? ? ? ? ? ? timeToLiveSeconds="120"
? ? ? ? ? ? diskSpoolBufferSizeMB="30"
? ? ? ? ? ? maxEntriesLocalDisk="10000000"
? ? ? ? ? ? diskExpiryThreadIntervalSeconds="120"
? ? ? ? ? ? memoryStoreEvictionPolicy="LRU">
? ? ? ?
? ?
?
? ? ? ? ? ? ? maxEntriesLocalHeap="10000"
? ? ? ? ? maxEntriesLocalDisk="1000"
? ? ? ? ? eternal="false"
? ? ? ? ? diskSpoolBufferSizeMB="30"
? ? ? ? ? timeToIdleSeconds="300"
? ? ? ? ? timeToLiveSeconds="600"
? ? ? ? ? memoryStoreEvictionPolicy="LFU"
? ? ? ? ? transactionalMode="off">
? ? ? ?
? ?
?


第二步:在spring.xml的配置文件中引入schema,


xmlns:aop="http://www.springframework.org/schema/aop"和http://www.springframework.org/schema/cache? http://www.springframework.org/schema/cache/spring-cache-3.2.xsd


缓存的配置:



? ?
? ?
? ?
? ?
? ? ? ?
? ?

? ?
? ?
? ? ? ?
? ?


OK!缓存的相关配置已经完成。下面开始编写测试程序。这里需要连接数据库,我就不写了。这里为了方便就随便找了之前写过的model,这个model就是AOP注解实现日志管理的实体,为了偷懒就直接用了,希望你们不要误解,没有特殊意义的


第三步:编写model,这里需要注意,要实现缓存的实体必须要序列化 private static final long serialVersionUID = -6579533328390250520L;? 关于序列化的生成这里就不介绍了,大家可以百度看看。


package org.shop.entity;


import java.io.Serializable;
import java.util.Date;


public class SystemLog implements Serializable {
?
? ? private static final long serialVersionUID = -6579533328390250520L;


? ? private String id;


? ? private String description;


? ? private String method;


? ? private Long logType;


? ? private String requestIp;


? ? private String exceptioncode;


? ? private String exceptionDetail;


? ? private String params;


? ? private String createBy;


? ? private Date createDate;


? ? public String getId() {
? ? ? ? return id;
? ? }


? ? public void setId(String id) {
? ? ? ? this.id = id == null ? null : id.trim();
? ? }


? ? public String getDescription() {
? ? ? ? return description;
? ? }


? ? public void setDescription(String description) {
? ? ? ? this.description = description == null ? null : description.trim();
? ? }


? ? public String getMethod() {
? ? ? ? return method;
? ? }


? ? public void setMethod(String method) {
? ? ? ? this.method = method == null ? null : method.trim();
? ? }


? ? public Long getLogType() {
? ? ? ? return logType;
? ? }


? ? public void setLogType(Long logType) {
? ? ? ? this.logType = logType;
? ? }


? ? public String getRequestIp() {
? ? ? ? return requestIp;
? ? }


? ? public void setRequestIp(String requestIp) {
? ? ? ? this.requestIp = requestIp == null ? null : requestIp.trim();
? ? }


? ? public String getExceptioncode() {
? ? ? ? return exceptioncode;
? ? }


? ? public void setExceptioncode(String exceptioncode) {
? ? ? ? this.exceptioncode = exceptioncode == null ? null : exceptioncode.trim();
? ? }


? ? public String getExceptionDetail() {
? ? ? ? return exceptionDetail;
? ? }


? ? public void setExceptionDetail(String exceptionDetail) {
? ? ? ? this.exceptionDetail = exceptionDetail == null ? null : exceptionDetail.trim();
? ? }


? ? public String getParams() {
? ? ? ? return params;
? ? }


? ? public void setParams(String params) {
? ? ? ? this.params = params == null ? null : params.trim();
? ? }


? ? public String getCreateBy() {
? ? ? ? return createBy;
? ? }


? ? public void setCreateBy(String createBy) {
? ? ? ? this.createBy = createBy == null ? null : createBy.trim();
? ? }


? ? public Date getCreateDate() {
? ? ? ? return createDate;
?

首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇使用Spring cache和ehcache之前必.. 下一篇C语言实现文件实时更新

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: