+ add XML support for cache abstraction (cache-advice) - DRAFT
This commit is contained in:
@@ -86,7 +86,7 @@ public abstract class AbstractAnnotationTests {
|
||||
Object r2 = service.cache(o1);
|
||||
|
||||
assertSame(r1, r2);
|
||||
service.invalidate(o1, null);
|
||||
service.evict(o1, null);
|
||||
Object r3 = service.cache(o1);
|
||||
Object r4 = service.cache(o1);
|
||||
assertNotSame(r1, r3);
|
||||
|
||||
@@ -43,7 +43,7 @@ public class AnnotatedClassCacheableService implements CacheableService {
|
||||
}
|
||||
|
||||
@CacheEvict(value = "default", key = "#p0")
|
||||
public void invalidate(Object arg1, Object arg2) {
|
||||
public void evict(Object arg1, Object arg2) {
|
||||
}
|
||||
|
||||
@Cacheable(value = "default", key = "#p0")
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright 2010-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cache.config;
|
||||
|
||||
|
||||
/**
|
||||
* @author Costin Leau
|
||||
*/
|
||||
public class CacheAdviceNamespaceTests extends AbstractAnnotationTests {
|
||||
|
||||
|
||||
@Override
|
||||
protected String getConfig() {
|
||||
return "/org/springframework/cache/config/cache-advice.xml";
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,7 @@ public interface CacheableService<T> {
|
||||
|
||||
void invalidate(Object arg1);
|
||||
|
||||
void invalidate(Object arg1, Object arg2);
|
||||
void evict(Object arg1, Object arg2);
|
||||
|
||||
T conditional(int field);
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ public class DefaultCacheableService implements CacheableService<Long> {
|
||||
}
|
||||
|
||||
@CacheEvict(value = "default", key = "#p0")
|
||||
public void invalidate(Object arg1, Object arg2) {
|
||||
public void evict(Object arg1, Object arg2) {
|
||||
}
|
||||
|
||||
@Cacheable(value = "default", condition = "#classField == 3")
|
||||
|
||||
59
org.springframework.context/src/test/resources/org/springframework/cache/config/cache-advice.xml
vendored
Normal file
59
org.springframework.context/src/test/resources/org/springframework/cache/config/cache-advice.xml
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:aop="http://www.springframework.org/schema/aop"
|
||||
xmlns:cache="http://www.springframework.org/schema/cache"
|
||||
xmlns:p="http://www.springframework.org/schema/p"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
|
||||
http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd">
|
||||
|
||||
<cache:advice id="cacheAdviceInterface" cache-manager="cacheManager">
|
||||
<cache:definitions cache="default">
|
||||
<cache:cacheable method="cache"/>
|
||||
<cache:cacheable method="conditional" condition="#classField == 3"/>
|
||||
<cache:cacheable method="key" key="#p0"/>
|
||||
<cache:cacheable method="nam*" key="#root.methodName"/>
|
||||
<cache:cacheable method="rootVars" key="#root.methodName + #root.method.name + #root.targetClass + #root.target"/>
|
||||
<cache:cacheable method="nullValue" cache="default"/>
|
||||
</cache:definitions>
|
||||
<cache:definitions>
|
||||
<cache:cache-evict method="invalidate" cache="default"/>
|
||||
<cache:cache-evict method="evict" key="#p0" cache="default"/>
|
||||
</cache:definitions>
|
||||
</cache:advice>
|
||||
|
||||
<cache:advice id="cacheAdviceClass" cache-manager="cacheManager">
|
||||
<cache:definitions cache="default">
|
||||
<cache:cacheable method="key" key="#p0"/>
|
||||
<cache:cacheable method="nam*" key="#root.methodName + #root.caches[0].name"/>
|
||||
<cache:cacheable method="rootVars" key="#root.methodName + #root.method.name + #root.targetClass + #root.target"/>
|
||||
<cache:cacheable method="cache"/>
|
||||
<cache:cacheable method="conditional"/>
|
||||
<cache:cacheable method="null*"/>
|
||||
</cache:definitions>
|
||||
<cache:definitions>
|
||||
<cache:cache-evict method="invalidate" cache="default"/>
|
||||
<cache:cache-evict method="evict" key="#p0" cache="default"/>
|
||||
</cache:definitions>
|
||||
</cache:advice>
|
||||
|
||||
<aop:config>
|
||||
<aop:advisor advice-ref="cacheAdviceInterface" pointcut="execution(* *..DefaultCacheableService.*(..))" order="1"/>
|
||||
<aop:advisor advice-ref="cacheAdviceClass" pointcut="execution(* *..AnnotatedClassCacheableService.*(..))" order="1"/>
|
||||
<aop:advisor advice-ref="debugInterceptor" pointcut="execution(* *..CacheableService.*(..))" order="2"/>
|
||||
</aop:config>
|
||||
|
||||
<bean id="cacheManager" class="org.springframework.cache.support.SimpleCacheManager">
|
||||
<property name="caches">
|
||||
<set>
|
||||
<bean class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean" p:name="default"/>
|
||||
</set>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="debugInterceptor" class="org.springframework.aop.interceptor.DebugInterceptor"/>
|
||||
|
||||
<bean id="service" class="org.springframework.cache.config.DefaultCacheableService"/>
|
||||
|
||||
<bean id="classService" class="org.springframework.cache.config.AnnotatedClassCacheableService"/>
|
||||
</beans>
|
||||
Reference in New Issue
Block a user