Skip to content

Commit

Permalink
Minor code improvements (#106)
Browse files Browse the repository at this point in the history
* Remove unused imports

* Fix typos
  • Loading branch information
darxriggs committed Mar 10, 2022
1 parent 9dfde44 commit 44e9450
Show file tree
Hide file tree
Showing 8 changed files with 6 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package grails.plugin.cache

import groovy.transform.CompileStatic
import groovy.transform.EqualsAndHashCode
import org.springframework.aop.framework.AopProxyUtils
import org.springframework.cache.interceptor.KeyGenerator
import org.springframework.cache.interceptor.SimpleKeyGenerator
Expand Down Expand Up @@ -187,4 +186,3 @@ class CustomCacheKeyGenerator implements KeyGenerator, GrailsCacheKeyGenerator {
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import org.codehaus.groovy.ast.stmt.Statement
import org.codehaus.groovy.control.SourceUnit
import org.codehaus.groovy.transform.trait.TraitComposer
import org.grails.datastore.gorm.multitenancy.transform.TenantTransform
import org.grails.datastore.gorm.transactions.transform.TransactionalTransform
import org.grails.datastore.gorm.transform.AbstractMethodDecoratingTransformation
import org.grails.datastore.gorm.transform.AbstractTraitApplyingGormASTTransformation
import org.grails.datastore.mapping.core.Ordered
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,14 @@ import org.codehaus.groovy.ast.stmt.Statement
import org.codehaus.groovy.control.CompilePhase
import org.codehaus.groovy.control.SourceUnit
import org.codehaus.groovy.transform.GroovyASTTransformation
import org.h2.schema.Constant
import org.springframework.cache.Cache

import static org.codehaus.groovy.ast.ClassHelper.make
import static org.codehaus.groovy.ast.tools.GeneralUtils.block
import static org.codehaus.groovy.ast.tools.GeneralUtils.callX
import static org.codehaus.groovy.ast.tools.GeneralUtils.declS
import static org.codehaus.groovy.ast.tools.GeneralUtils.ifS
import static org.codehaus.groovy.ast.tools.GeneralUtils.notNullX
import static org.codehaus.groovy.ast.tools.GeneralUtils.stmt
import static org.codehaus.groovy.ast.tools.GeneralUtils.varX
import static org.grails.datastore.gorm.transform.AstMethodDispatchUtils.callD

/**
* Implementation of {@link CacheEvict}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@ import groovy.transform.CompileStatic
import org.codehaus.groovy.ast.AnnotationNode
import org.codehaus.groovy.ast.ClassNode
import org.codehaus.groovy.ast.MethodNode
import org.codehaus.groovy.ast.expr.ClosureExpression
import org.codehaus.groovy.ast.expr.Expression
import org.codehaus.groovy.ast.expr.MethodCallExpression
import org.codehaus.groovy.ast.expr.VariableExpression
import org.codehaus.groovy.ast.stmt.BlockStatement
import org.codehaus.groovy.ast.stmt.Statement
import org.codehaus.groovy.control.CompilePhase
import org.codehaus.groovy.control.SourceUnit
import org.codehaus.groovy.transform.GroovyASTTransformation
Expand Down
2 changes: 1 addition & 1 deletion src/main/docs/guide/usage/cacheManager.adoc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
The plugin registers an instance of the link:{springApi}/org/springframework/cache/CacheManager.html[CacheManager] iterface as the `grailsCacheManager` Spring bean, so it's easy to access using dependency injection.
The plugin registers an instance of the link:{springApi}/org/springframework/cache/CacheManager.html[CacheManager] interface as the `grailsCacheManager` Spring bean, so it's easy to access using dependency injection.

The most common method you would call on the `grailsCacheManager` is `getCache(String name)` to access a link:{springApi}/org/springframework/cache/Cache.html[Cache] instance programmatically. This shouldn't be needed often however. From the `Cache` instance you can also access the underlying cache implementation using `cache.getNativeCache()`.
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ class BasicCachingServiceNoCacheManagerSpec extends Specification implements Ser
when: 'a cached method is invoked the first time'
def result = service.getData()

then: 'the code in the method is exeucted'
then: 'the code in the method is executed'
result == 'Hello World!'
service.invocationCounter == 1

when: 'a cached method is invoked the second time'
result = service.getData()

then: 'the code in the method is still exeucted because no cache manager is present'
then: 'the code in the method is still executed because no cache manager is present'
result == 'Hello World!'
service.invocationCounter == 2
}
Expand Down
6 changes: 3 additions & 3 deletions src/test/groovy/com/demo/BasicCachingServiceSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class BasicCachingServiceSpec extends Specification implements ServiceUnitTest<B
when: 'a cached method is invoked the first time'
def result = service.getData()

then: 'the code in the method is exeucted'
then: 'the code in the method is executed'
result == 'Hello World!'
service.invocationCounter == 1

Expand All @@ -30,7 +30,7 @@ class BasicCachingServiceSpec extends Specification implements ServiceUnitTest<B
}

void 'test invoking a cacheable method that expresses a condition'() {
when: 'mutliply is called with x < 10'
when: 'multiply is called with x < 10'
def result = service.multiply(4, 7)

then: 'the method should have been invoked'
Expand All @@ -44,7 +44,7 @@ class BasicCachingServiceSpec extends Specification implements ServiceUnitTest<B
result == 280
service.conditionalInvocationCounter == 2

when: 'mutliply is called with x < 10 with a cached value'
when: 'multiply is called with x < 10 with a cached value'
result = service.multiply(4, 7)

then: 'the method should not have executed'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import org.grails.datastore.mapping.multitenancy.resolvers.SystemPropertyTenantR
import org.grails.datastore.mapping.simple.SimpleMapDatastore
import org.grails.plugin.cache.GrailsCacheManager
import org.springframework.cache.Cache
import org.springframework.cache.CacheManager
import spock.lang.Specification

/**
Expand Down

0 comments on commit 44e9450

Please sign in to comment.