Skip to content

Commit

Permalink
Updated cache config to work without /data in development #929
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisala committed Jun 13, 2024
1 parent 134b2f6 commit 8c8ee76
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 13 deletions.
16 changes: 4 additions & 12 deletions grails-app/conf/application.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,7 @@ if (!grails.cache.ehcache) {
}
}
}
ehcache.directory='/data/ecodata/ehcache'


security {
Expand Down Expand Up @@ -623,16 +624,11 @@ environments {
app.uploads.url = "/document/download/"
grails.mail.host="localhost"
grails.mail.port=1025

ehcache.directory="./ehcache"

}
test {
// Override disk store so the travis build doesn't fail.
grails.cache.ehcache = {
diskStore {
path '/tmp'
}
}
ehcache.directory="./ehcache"
grails.logging.jul.usebridge = true
ecodata.use.uuids = false
app.external.model.dir = "./models/"
Expand All @@ -657,11 +653,7 @@ environments {
security.cas.loginUrl="${security.cas.casServerUrlPrefix}/login"
}
meritfunctionaltest {
grails.cache.ehcache = {
diskStore {
path '/tmp'
}
}
ehcache.directory="./ehcache"
security.cas.bypass = true
grails.logging.jul.usebridge = true
ecodata.use.uuids = false
Expand Down
17 changes: 16 additions & 1 deletion grails-app/conf/ecodata-ehcache.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
xmlns='http:https://www.ehcache.org/v3'
xmlns:jsr107='http:https://www.ehcache.org/v3/jsr107'>

<persistence directory="/data/ecodata/ehcache"/>
<persistence directory="${ehcache.directory}"/>

<cache alias="spatialGeoJsonPid" uses-template="defaultSetting">
<expiry>
Expand Down Expand Up @@ -38,6 +38,21 @@
<heap unit="entries">100</heap>
</resources>
</cache>
<cache alias="spatialGeoJsonPidObjectGeometry">

<key-type>java.io.Serializable</key-type>
<value-type>java.io.Serializable</value-type>

<expiry>
<tti unit="days">45</tti>
</expiry>
<resources>
<heap unit="entries">100</heap>

<disk unit="MB" persistent="true">500</disk>
</resources>
</cache>

<cache alias="grailsTemplatesCache">
<key-type>java.io.Serializable</key-type>
<value-type>java.io.Serializable</value-type>
Expand Down
22 changes: 22 additions & 0 deletions grails-app/init/au/org/ala/ecodata/Application.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import au.org.ala.userdetails.UserDetailsClient
import com.squareup.moshi.Moshi
import com.squareup.moshi.Rfc3339DateJsonAdapter
import grails.boot.GrailsApp
import grails.boot.config.GrailsApplicationPostProcessor
import grails.boot.config.GrailsAutoConfiguration
import grails.core.GrailsApplication
import graphql.Scalars
Expand All @@ -30,6 +31,9 @@ import org.springframework.context.annotation.ComponentScan
//@Slf4j
class Application extends GrailsAutoConfiguration {

private static final String EHCACHE_DIRECTORY_CONFIG_ITEM = "ehcache.directory"
private static final String DEFAULT_EHCACHE_DIRECTORY = "./ehcache"

static void main(String[] args) {
GrailsApp.run(Application, args)
}
Expand All @@ -48,4 +52,22 @@ class Application extends GrailsAutoConfiguration {
SchemaGenerator schemaGenerator = new SchemaGenerator();
return schemaGenerator.makeExecutableSchema(typeDefinitionRegistry, runtimeWiring);
}

@Bean
GrailsApplicationPostProcessor grailsApplicationPostProcessor() {

// We are overriding the GrailsApplicationPostProcessor because we need a lifecycle hook after
// the configuration has been read, but before the plugin lifecycle bean initialisation has started.
// This is because the grails ehcache plugin only supports configuration via XML files and the
// cache directory store can only be configured via an environment variable.
// To keep the configuration in one place, we are reading the config, and setting the system property
// so it can be read during cache initialisation.
return new GrailsApplicationPostProcessor( this, applicationContext, classes() as Class[]) {
@Override
protected void customizeGrailsApplication(GrailsApplication grailsApplication) {
System.setProperty(EHCACHE_DIRECTORY_CONFIG_ITEM, grailsApplication.config.getProperty(EHCACHE_DIRECTORY_CONFIG_ITEM, DEFAULT_EHCACHE_DIRECTORY))
}

}
}
}

0 comments on commit 8c8ee76

Please sign in to comment.