Skip to content

Commit

Permalink
Cleanup / upgrade to Grails 3.2.8
Browse files Browse the repository at this point in the history
  • Loading branch information
Graeme Rocher authored and Graeme Rocher committed Apr 18, 2017
1 parent 5074e39 commit c8c9cfc
Show file tree
Hide file tree
Showing 12 changed files with 126 additions and 147 deletions.
4 changes: 4 additions & 0 deletions build.gradle
Expand Up @@ -46,13 +46,17 @@ dependencies {
profile "org.grails.profiles:web-plugin"
provided "org.grails:grails-plugin-services"
provided "org.grails:grails-plugin-domain-class"

testCompile "org.grails:grails-datastore-gorm-test"
testCompile "org.grails:grails-plugin-testing"
testCompile "org.grails.plugins:geb"
testRuntime "org.seleniumhq.selenium:selenium-htmlunit-driver:2.47.1"
testRuntime "net.sourceforge.htmlunit:htmlunit:2.18"

compile "com.googlecode.concurrentlinkedhashmap:concurrentlinkedhashmap-lru:1.4.2"
compile "org.javassist:javassist:3.17.1-GA"


}

task wrapper(type: Wrapper) {
Expand Down
3 changes: 2 additions & 1 deletion gradle.properties
@@ -1,2 +1,3 @@
grailsVersion=3.2.1
grailsVersion=3.2.8
gormVersion=6.1.1.RELEASE
gradleWrapperVersion=3.0
Expand Up @@ -14,25 +14,26 @@
*/
package grails.plugin.cache

import grails.plugin.cache.CacheEvict
import groovy.transform.CompileStatic

@CompileStatic
class GrailsCacheAdminService {

static transactional = false

GrailsCacheManager grailsCacheManager

@CacheEvict(value="grailsBlocksCache")
def clearBlocksCache() {}
void clearBlocksCache() {}

@CacheEvict(value="grailsTemplatesCache")
def clearTemplatesCache() {}
void clearTemplatesCache() {}

def clearCache(cacheName) {
void clearCache(cacheName) {
grailsCacheManager.getCache(cacheName)?.clear()
}

def clearAllCaches() {
void clearAllCaches() {
grailsCacheManager.cacheNames.each { cacheName ->
clearCache(cacheName)
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/groovy/grails/plugin/cache/CacheException.groovy
@@ -1,5 +1,7 @@
package grails.plugin.cache

import groovy.transform.CompileStatic

/**
* A runtime Cache Exception.
* <p/>
Expand All @@ -10,6 +12,7 @@ package grails.plugin.cache
* @author James Kleeh
*
*/
@CompileStatic
class CacheException extends RuntimeException {

/**
Expand Down
18 changes: 4 additions & 14 deletions src/main/groovy/grails/plugin/cache/CacheGrailsPlugin.groovy
Expand Up @@ -23,21 +23,11 @@ import org.springframework.cache.Cache
@Slf4j
class CacheGrailsPlugin extends Plugin {

def grailsVersion = "3.2.0 > *"
def grailsVersion = "3.3.0 > *"
def observe = ['controllers', 'services']
def loadAfter = ['controllers', 'services']
def title = 'Cache Plugin'
def author = 'Jeff Brown'
def authorEmail = 'brownj@ociweb.com'
def description = 'Grails Cache Plugin'
def documentation = 'http://grails3-plugins.github.com/cache/latest'
def profiles = ['web']
def license = 'APACHE'
def organization = [name: 'SpringSource', url: 'http://www.springsource.org/']
def developers = [[name: 'Burt Beckwith', email: 'beckwithb@vmware.com']]
def issueManagement = [system: 'GITHUB', url: 'https://github.com/grails-plugins/grails-cache/issues']
def scm = [url: 'https://github.com/grails-plugins/grails-cache']


// resources that should be loaded by the plugin once installed in the application
//Does this even work anymore? Doesn't appear to.
Expand Down Expand Up @@ -85,9 +75,9 @@ class CacheGrailsPlugin extends Plugin {
}

List<String> defaultCaches = ['grailsBlocksCache', 'grailsTemplatesCache']
defaultCaches.each {
if (!grailsCacheManager.cacheExists(it)) {
grailsCacheManager.getCache(it)
for(name in defaultCaches) {
if (!grailsCacheManager.cacheExists(name)) {
grailsCacheManager.getCache(name)
}
}
}
Expand Down
@@ -1,7 +1,15 @@
package grails.plugin.cache

import groovy.transform.CompileStatic
import org.springframework.boot.context.properties.ConfigurationProperties

/**
* Configuration properties for the cache plugin
*
* @author Graeme Rocher
* @author James Kleeh
*/
@CompileStatic
@ConfigurationProperties(value = 'grails.cache')
class CachePluginConfiguration {

Expand Down
184 changes: 74 additions & 110 deletions src/main/groovy/grails/plugin/cache/CustomCacheKeyGenerator.groovy
Expand Up @@ -12,112 +12,114 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package grails.plugin.cache;
package grails.plugin.cache

import grails.plugins.GrailsVersionUtils
import groovy.transform.CompileStatic;
import org.springframework.aop.framework.AopProxyUtils;
import org.springframework.cache.interceptor.KeyGenerator;
import org.springframework.core.SpringVersion;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.StandardEvaluationContext;
import groovy.transform.CompileStatic
import groovy.transform.EqualsAndHashCode
import org.springframework.aop.framework.AopProxyUtils
import org.springframework.cache.interceptor.KeyGenerator
import org.springframework.core.SpringVersion
import org.springframework.expression.spel.standard.SpelExpressionParser
import org.springframework.expression.spel.support.StandardEvaluationContext

import java.io.Serializable;
import java.lang.reflect.Method;
import java.util.Map;
import java.io.Serializable
import java.lang.reflect.Method
import java.util.Map

/**
* Includes the hashcode, method signature, and class name of the target (caller) in the cache key
*/
@CompileStatic
public class CustomCacheKeyGenerator implements KeyGenerator, GrailsCacheKeyGenerator {
class CustomCacheKeyGenerator implements KeyGenerator, GrailsCacheKeyGenerator {

private final KeyGenerator innerKeyGenerator;
public CustomCacheKeyGenerator(KeyGenerator innerKeyGenerator){
this.innerKeyGenerator = innerKeyGenerator;
private final KeyGenerator innerKeyGenerator

CustomCacheKeyGenerator(KeyGenerator innerKeyGenerator){
this.innerKeyGenerator = innerKeyGenerator
}
public CustomCacheKeyGenerator(){

CustomCacheKeyGenerator(){
// Use the Spring key generator if the Spring version is 4.0.3 or later
// Can't use the Spring key generator if < 4.0.3 because of https://jira.spring.io/browse/SPR-11505
if(SpringVersion.getVersion()==null || GrailsVersionUtils.isVersionGreaterThan(SpringVersion.getVersion(),"4.0.3")){
this.innerKeyGenerator = new SimpleKeyGenerator();
this.innerKeyGenerator = new SimpleKeyGenerator()
}else{
try {
this.innerKeyGenerator = (KeyGenerator) Class.forName("org.springframework.cache.interceptor.SimpleKeyGenerator").newInstance();
this.innerKeyGenerator = (KeyGenerator) Class.forName("org.springframework.cache.interceptor.SimpleKeyGenerator").newInstance()
} catch (Exception e) {
// this should never happen
throw new RuntimeException(e);
throw new RuntimeException(e)
}
}
}

@SuppressWarnings("serial")
private static final class CacheKey implements Serializable {
final String targetClassName;
final String targetMethodName;
final int targetObjectHashCode;
final Object simpleKey;
public CacheKey(String targetClassName, String targetMethodName,
int targetObjectHashCode, Object simpleKey) {
this.targetClassName = targetClassName;
this.targetMethodName = targetMethodName;
this.targetObjectHashCode = targetObjectHashCode;
this.simpleKey = simpleKey;
final String targetClassName
final String targetMethodName
final int targetObjectHashCode
final Object simpleKey

CacheKey(String targetClassName, String targetMethodName,
int targetObjectHashCode, Object simpleKey) {
this.targetClassName = targetClassName
this.targetMethodName = targetMethodName
this.targetObjectHashCode = targetObjectHashCode
this.simpleKey = simpleKey
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
int hashCode() {
final int prime = 31
int result = 1
result = prime * result
+ ((simpleKey == null) ? 0 : simpleKey.hashCode());
+ ((simpleKey == null) ? 0 : simpleKey.hashCode())
result = prime * result
+ ((targetClassName == null) ? 0 : targetClassName
.hashCode());
.hashCode())
result = prime * result
+ ((targetMethodName == null) ? 0 : targetMethodName
.hashCode());
result = prime * result + targetObjectHashCode;
return result;
.hashCode())
result = prime * result + targetObjectHashCode
return result
}
@Override
public boolean equals(Object obj) {
boolean equals(Object obj) {
if (this == obj)
return true;
return true
if (obj == null)
return false;
return false
if (getClass() != obj.getClass())
return false;
CacheKey other = (CacheKey) obj;
return false
CacheKey other = (CacheKey) obj
if (simpleKey == null) {
if (other.simpleKey != null)
return false;
return false
} else if (!simpleKey.equals(other.simpleKey))
return false;
return false
if (targetClassName == null) {
if (other.targetClassName != null)
return false;
return false
} else if (!targetClassName.equals(other.targetClassName))
return false;
return false
if (targetMethodName == null) {
if (other.targetMethodName != null)
return false;
return false
} else if (!targetMethodName.equals(other.targetMethodName))
return false;
return false
if (targetObjectHashCode != other.targetObjectHashCode)
return false;
return true;
return false
return true
}
}

public Object generate(Object target, Method method, Object... params) {
Class<?> objClass = AopProxyUtils.ultimateTargetClass(target);
Object generate(Object target, Method method, Object... params) {
Class<?> objClass = AopProxyUtils.ultimateTargetClass(target)

return new CacheKey(
objClass.getName().intern(),
method.toString().intern(),
target.hashCode(), innerKeyGenerator.generate(target, method, params));
target.hashCode(), innerKeyGenerator.generate(target, method, params))
}

@Override
Expand All @@ -139,61 +141,23 @@ public class CustomCacheKeyGenerator implements KeyGenerator, GrailsCacheKeyGene

new TemporaryGrailsCacheKey(className, methodName, objHashCode, simpleKey)
}
}

class TemporaryGrailsCacheKey implements Serializable {
final String targetClassName;
final String targetMethodName;
final int targetObjectHashCode;
final Object simpleKey;
public TemporaryGrailsCacheKey(String targetClassName, String targetMethodName,
int targetObjectHashCode, Object simpleKey) {
this.targetClassName = targetClassName;
this.targetMethodName = targetMethodName;
this.targetObjectHashCode = targetObjectHashCode;
this.simpleKey = simpleKey;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((simpleKey == null) ? 0 : simpleKey.hashCode());
result = prime * result
+ ((targetClassName == null) ? 0 : targetClassName
.hashCode());
result = prime * result
+ ((targetMethodName == null) ? 0 : targetMethodName
.hashCode());
result = prime * result + targetObjectHashCode;
return result;
}
@Override
public boolean equals(Object obj) {
if (this.is(obj))
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
TemporaryGrailsCacheKey other = (TemporaryGrailsCacheKey) obj;
if (simpleKey == null) {
if (other.simpleKey != null)
return false;
} else if (!simpleKey.equals(other.simpleKey))
return false;
if (targetClassName == null) {
if (other.targetClassName != null)
return false;
} else if (!targetClassName.equals(other.targetClassName))
return false;
if (targetMethodName == null) {
if (other.targetMethodName != null)
return false;
} else if (!targetMethodName.equals(other.targetMethodName))
return false;
if (targetObjectHashCode != other.targetObjectHashCode)
return false;
return true;
@EqualsAndHashCode
@CompileStatic
private static class TemporaryGrailsCacheKey implements Serializable {
final String targetClassName
final String targetMethodName
final int targetObjectHashCode
final Object simpleKey

TemporaryGrailsCacheKey(String targetClassName, String targetMethodName,
int targetObjectHashCode, Object simpleKey) {
this.targetClassName = targetClassName
this.targetMethodName = targetMethodName
this.targetObjectHashCode = targetObjectHashCode
this.simpleKey = simpleKey
}
}

}

1 change: 1 addition & 0 deletions src/main/groovy/grails/plugin/cache/GrailsCache.java
Expand Up @@ -20,6 +20,7 @@

/**
* @author Burt Beckwith
* @since 1.0
*/
public interface GrailsCache extends Cache {

Expand Down
11 changes: 11 additions & 0 deletions src/main/groovy/grails/plugin/cache/GrailsCacheManager.java
Expand Up @@ -21,7 +21,18 @@
*/
public interface GrailsCacheManager extends CacheManager {

/**
* Whether the cache for the given name exits
*
* @param name The name of the cache
* @return True if it does
*/
boolean cacheExists(String name);

/**
* Destroys the given named cache
* @param name The name of the cache
* @return True if it was destroyed
*/
boolean destroyCache(String name);
}

0 comments on commit c8c9cfc

Please sign in to comment.