-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathSpringcacheGrailsPlugin.groovy
More file actions
120 lines (101 loc) · 3.21 KB
/
SpringcacheGrailsPlugin.groovy
File metadata and controls
120 lines (101 loc) · 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator
import org.slf4j.LoggerFactory
import org.springframework.cache.ehcache.*
import grails.plugin.springcache.aop.CachingAspect
import grails.plugin.springcache.aop.FlushingAspect
import grails.plugin.springcache.web.GrailsFragmentCachingFilter
import org.springframework.web.filter.DelegatingFilterProxy
import grails.plugin.springcache.web.key.DefaultKeyGenerator
class SpringcacheGrailsPlugin {
def version = "1.2"
def grailsVersion = "1.2-M3 > *"
def dependsOn = [:]
def pluginExcludes = [
"grails-app/views/**",
"web-app/**",
"**/.gitignore"
]
def author = "Rob Fletcher"
def authorEmail = "rob@energizedwork.com"
def title = "Spring Cache Plugin"
def description = "Allows caching and flushing aspects to be added to Grails services using annotations."
def documentation = "http://grails.org/Springcache+Plugin"
def doWithWebDescriptor = {xml ->
if (!application.config.springcache.disabled) {
def filters = xml.filter
def lastFilter = filters[filters.size() - 1]
lastFilter + {
filter {
"filter-name" "springcacheContentCache"
"filter-class" DelegatingFilterProxy.name
"init-param" {
"param-name" "targetBeanName"
"param-value" "springcacheFilter"
}
"init-param" {
"param-name" "targetFilterLifecycle"
"param-value" "true"
}
}
}
def filterMappings = xml."filter-mapping"
def lastMapping = filterMappings[filterMappings.size() - 1]
lastMapping + {
"filter-mapping" {
"filter-name" "springcacheContentCache"
"url-pattern" "*.dispatch"
dispatcher "FORWARD"
dispatcher "INCLUDE"
}
}
}
}
def doWithSpring = {
if (application.config.springcache.disabled) {
log.warn "Springcache plugin is disabled"
} else {
springcacheAutoProxyCreator(AnnotationAwareAspectJAutoProxyCreator) {
proxyTargetClass = true
}
springcacheCacheManager(EhCacheManagerFactoryBean) {
cacheManagerName = "Springcache Plugin Cache Manager"
}
springcacheDefaultCache(EhCacheFactoryBean) { bean ->
bean."abstract" = true
application.config.springcache.defaults.each {
cacheManager = ref("springcacheCacheManager")
bean.setPropertyValue it.key, it.value
}
}
application.config.springcache.caches.each {String name, ConfigObject cacheConfig ->
"$name"(EhCacheFactoryBean) {bean ->
bean.parent = springcacheDefaultCache
cacheName = name
cacheConfig.each {
bean.setPropertyValue it.key, it.value
}
}
}
springcacheCachingAspect(CachingAspect) {
springcacheService = ref("springcacheService")
}
springcacheFlushingAspect(FlushingAspect) {
springcacheService = ref("springcacheService")
}
springcacheFilter(GrailsFragmentCachingFilter) {
springcacheService = ref("springcacheService")
cacheManager = ref("springcacheCacheManager")
keyGenerator = new DefaultKeyGenerator()
}
}
}
def doWithDynamicMethods = {ctx ->
}
def doWithApplicationContext = {applicationContext ->
}
def onChange = {event ->
}
def onConfigChange = {event ->
}
private static final log = LoggerFactory.getLogger("grails.plugin.springcache.SpringcacheGrailsPlugin")
}