Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fixes #GPCACHE-20: Disable the plugin via configuration property #1

Merged
merged 2 commits into from

2 participants

@nwittstruck

This should fix http://jira.grails.org/browse/GPCACHE-20

The config property defaults to true, so the plugin is enabled by default.

@burtbeckwith burtbeckwith merged commit a517b58 into grails-plugins:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 2, 2013
  1. GPCACHE-20 added docs

    nwittstruck authored
This page is out of date. Refresh to see the latest.
View
10 CacheGrailsPlugin.groovy
@@ -190,12 +190,18 @@ class CacheGrailsPlugin {
}
private void reloadCaches(ctx) {
+
+ if (!isEnabled(ctx.grailsApplication)) {
+ return
+ }
+
ctx.grailsCacheConfigLoader.reload ctx
log.debug 'Reloaded grailsCacheConfigLoader'
}
private boolean isEnabled(GrailsApplication application) {
- // TODO
- true
+ application.config.grails.cache.with {
+ (enabled == null || enabled != false)
+ }
}
}
View
52 grails-app/taglib/grails/plugin/cache/CacheTagLib.groovy
@@ -34,21 +34,26 @@ class CacheTagLib {
* @attr key An optional cache key allowing the same block to be cached with different content
*/
def block = { attrs, body ->
- def cache = grailsCacheManager.getCache('grailsBlocksCache')
- def bodyClosure = ClassUtils.getPropertyOrFieldValue(body, 'bodyClosure')
- def closureClass = bodyClosure.getClass()
- def key = closureClass.getName()
- if (attrs.key) {
- key = key + ':' + attrs.key
+ if (grailsCacheManager) {
+ def cache = grailsCacheManager.getCache('grailsBlocksCache')
+ def bodyClosure = ClassUtils.getPropertyOrFieldValue(body, 'bodyClosure')
+ def closureClass = bodyClosure.getClass()
+ def key = closureClass.getName()
+ if (attrs.key) {
+ key = key + ':' + attrs.key
+ }
+ def content = cache.get(key)
+ if (content == null) {
+ content = body()
+ cache.put(key, content)
+ } else {
+ content = content.get()
+ }
+ out << content
}
- def content = cache.get(key)
- if (content == null) {
- content = body()
- cache.put(key, content)
- } else {
- content = content.get()
+ else {
+ out << body()
}
- out << content
}
/**
@@ -70,15 +75,20 @@ class CacheTagLib {
key = key + ':' + attrs.key
}
- def cache = grailsCacheManager.getCache('grailsTemplatesCache')
- def content = cache.get(key)
- if (content == null) {
- content = g.render(attrs)
- cache.put(key, content)
- } else {
- content = content.get()
+ if (grailsCacheManager) {
+ def cache = grailsCacheManager.getCache('grailsTemplatesCache')
+ def content = cache.get(key)
+ if (content == null) {
+ content = g.render(attrs)
+ cache.put(key, content)
+ } else {
+ content = content.get()
+ }
+ out << content
+ }
+ else {
+ out << g.render(attrs)
}
- out << content
}
protected String calculateFullKey(String templateName, String contextPath, String pluginName) {
View
1  src/docs/guide/usage/configuration.gdoc
@@ -6,6 +6,7 @@ There are a few configuration options for the plugin; these are specified in @Co
{table}
*Property* | *Default* | *Description*
+grails.cache.enabled | @true@ | Whether to enable the plugin
grails.cache.proxyTargetClass | @false@ | From the Spring Javadoc: "By default, all proxies are created as JDK proxies. This may cause some problems if you are injecting objects as concrete classes rather than interfaces. To overcome this restriction you can set the @proxy-target-class@ attribute to @true@ which will result in class-based proxies being created."
grails.cache.aopOrder | Ordered.LOWEST_PRECEDENCE | From the Spring docs: "Defines the order of the cache advice that is applied to beans annotated with \@Cacheable or \@CacheEvict. No specified ordering means that the AOP subsystem determines the order of the advice."
grails.cache.clearAtStartup | @false@ | Whether to clear all caches at startup
Something went wrong with that request. Please try again.