@@ -95,7 +95,7 @@ Redis 配置:
9595 <!-- 可以通过implements com.jarvis.cache.serializer.ISerializer<Object> 实现 Kryo 和 FST Serializer 工具,框架的核对不在这里,所以不提供过多的实现 -->
9696 <bean id="hessianSerializer" class="com.jarvis.cache.serializer.HessianSerializer" />
9797
98- <bean id="cachePointCut " class="com.jarvis.cache.redis.ShardedCachePointCut" destroy-method="destroy">
98+ <bean id="cacheManager " class="com.jarvis.cache.redis.ShardedCachePointCut" destroy-method="destroy">
9999 <constructor-arg ref="autoLoadConfig" />
100100 <property name="serializer" ref="hessianSerializer" />
101101 <property name="shardedJedisPool" ref="shardedJedisPool" />
@@ -123,7 +123,7 @@ Memcache 配置:
123123 </bean>
124124
125125 <bean id="hessianSerializer" class="com.jarvis.cache.serializer.HessianSerializer" />
126- <bean id="cachePointCut " class="com.jarvis.cache.memcache.CachePointCut" destroy-method="destroy">
126+ <bean id="cacheManager " class="com.jarvis.cache.memcache.CachePointCut" destroy-method="destroy">
127127 <constructor-arg ref="autoLoadConfig" />
128128 <property name="serializer" ref="hessianSerializer" />
129129 <property name="memcachedClient", ref="memcachedClient" />
@@ -137,12 +137,15 @@ Memcache 配置:
137137
138138###AOP 配置:
139139
140+ <bean id="cacheInterceptor" class="com.jarvis.cache.aop.aspectj.AspectjAopInterceptor">
141+ <property name="cacheManager" ref="cacheManager" />
142+ </bean>
140143 <aop:config proxy-target-class="true">
141- <aop:aspect ref="cachePointCut ">
144+ <aop:aspect ref="cacheInterceptor ">
142145 <aop:pointcut id="daoCachePointcut" expression="execution(public !void com.jarvis.cache_example.common.dao..*.*(..)) && @annotation(cache)" />
143146 <aop:around pointcut-ref="daoCachePointcut" method="proceed" />
144147 </aop:aspect>
145- <aop:aspect ref="cachePointCut " order="1000"><!-- order 参数控制 aop通知的优先级,值越小,优先级越高 ,在事务提交后删除缓存 -->
148+ <aop:aspect ref="cacheInterceptor " order="1000"><!-- order 参数控制 aop通知的优先级,值越小,优先级越高 ,在事务提交后删除缓存 -->
146149 <aop:pointcut id="deleteCachePointcut" expression="execution(* com.jarvis.cache_example.common.dao..*.*(..)) && @annotation(cacheDelete)" />
147150 <aop:after-returning pointcut-ref="deleteCachePointcut" method="deleteCache" returning="retVal"/>
148151 </aop:aspect>
@@ -151,7 +154,20 @@ Memcache 配置:
151154
152155通过Spring配置,能更好地支持,不同的数据使用不同的缓存服务器的情况。
153156
154- *** 注意*** 如果需要在MyBatis Mapper中使用,则需要使用com.jarvis.cache.mybatis.CachePointCutProxy 来处理。
157+ *** 注意*** 如果需要在MyBatis Mapper中使用,则需按如下配置:
158+
159+ <!-- proxy-target-class=false为jdk代理,为true的话,会导致拦截不了mybatis的mapper -->
160+ <aop:config proxy-target-class="false">
161+ <!-- 拦截mybatis的mapper -->
162+ <aop:aspect ref="cacheInterceptor">
163+ <aop:pointcut id="daoCachePointcut1" expression="execution(public !void com.jarvis.cache_example.common.mapper..*.*(..))" />
164+ <aop:around pointcut-ref="daoCachePointcut1" method="checkAndProceed" />
165+ </aop:aspect>
166+ <aop:aspect ref="cacheInterceptor" order="1000"><!-- order 参数控制 aop通知的优先级,值越小,优先级越高 ,在事务提交后删除缓存 -->
167+ <aop:pointcut id="deleteCachePointcut1" expression="execution(* com.jarvis.cache_example.common.mapper..*.*(..))" />
168+ <aop:after-returning pointcut-ref="deleteCachePointcut1" method="checkAndDeleteCache" returning="retVal" />
169+ </aop:aspect>
170+ </aop:config>
155171
156172###3 . 将需要使用缓存操作的方法前增加 @Cache 和 @CacheDelete 注解(Redis为例子)
157173
@@ -530,7 +546,13 @@ web.xml配置:
530546
531547## 更新日志
532548
533- * ####4 .0 对AOP实现可扩展
549+ * ####4 .0 实现AOP的可扩展
550+
551+ 受网友Rekoe 将AutoLoadCache 和 nutz整合的启发([ https://github.com/Rekoe/AutoLoadCache ] ( https://github.com/Rekoe/AutoLoadCache ) ),将AutoLoadCache 中的AOP相关功能进行抽取,以达到可扩展
552+
553+ * 把AOP拦截方法从AbstractCacheManager中抽取出来,并使用CacheAopProxyChain 和 DeleteCacheAopProxyChain 两个代理类进行封装拦截到的请求。
554+ * 实现了使用Aspectj进行AOP拦截:com.jarvis.cache.aop.aspectj.AspectjAopInterceptor
555+ * 升级时一定要注意配置文件的变化,可以参考[ cache-example] ( https://github.com/qiujiayu/cache-example ) 中的配置
534556
535557* ####3 .7 细节优化:
536558
0 commit comments