|
1
|
1 |
|
package io.mcarle.sciurus.cache; |
|
2
|
|
|
|
|
3
|
|
|
import io.mcarle.sciurus.Sciurus; |
|
4
|
|
|
import io.mcarle.sciurus.annotation.Cache; |
|
5
|
|
|
import org.aspectj.lang.ProceedingJoinPoint; |
|
6
|
|
|
import org.aspectj.lang.annotation.Around; |
|
7
|
|
|
import org.aspectj.lang.annotation.Aspect; |
|
8
|
|
|
import org.aspectj.lang.annotation.Pointcut; |
|
9
|
|
|
|
|
10
|
|
|
@Aspect |
|
11
|
1 |
|
public class CacheAspect { |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Matches any execution of any method returning a serializable result |
|
15
|
|
|
*/ |
|
16
|
|
|
@Pointcut("execution((java.io.Serializable+ || byte || short || int || long || float || double || char || boolean) *(..))") |
|
17
|
|
|
void anyMethodReturningSerializable() { |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Matches any execution of any method with at least one non serializable parameter |
|
22
|
|
|
*/ |
|
23
|
|
|
@Pointcut("execution(* *(.., !(java.io.Serializable+ || byte || short || int || long || float || double || char || boolean), ..))") |
|
24
|
|
|
void anyMethodWithMinimumOneNonSerializableParameter() { |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Matches any method, which is annotated with {@link Cache} |
|
29
|
|
|
*/ |
|
30
|
|
|
@Pointcut("@annotation(cache)") |
|
31
|
|
|
void cacheAnnotated(Cache cache) { |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
@Around(value = "anyMethodReturningSerializable() && !anyMethodWithMinimumOneNonSerializableParameter() && cacheAnnotated(cache)", argNames = "joinPoint,cache") |
|
35
|
|
|
public Object startedAndExecutionOfAnyMethodAnnotatedWithCache( |
|
36
|
|
|
ProceedingJoinPoint joinPoint, |
|
37
|
|
|
Cache cache |
|
38
|
|
|
) throws Throwable { |
|
39
|
1 |
|
if (Sciurus.isCacheStarted()) { |
|
40
|
1 |
|
return CacheAspectHandler.executeAndCache(joinPoint, cache); |
|
41
|
|
|
} else { |
|
42
|
1 |
|
return joinPoint.proceed(); |
|
43
|
|
|
} |
|
44
|
|
|
} |
|
45
|
|
|
} |
|
46
|
|
|
|