Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6917357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:43:13+00:00 2026-05-27T09:43:13+00:00

We’ve built a web app in Grails/Groovy. In groovy, we built a pluggable caching

  • 0

We’ve built a web app in Grails/Groovy. In groovy, we built a pluggable caching component to provide caching of large http response streams in the Grails app. We want to inject the cache implementation at runtime based on environment, for example, when a developer is doing some local work, inject a simple Map-based cache, but in an operational environment, inject a RDBMS cache database, you get the point.

We found this reference in the Grails tutorial which uses SWITCH, and it seems to work, but it’s ugly and cumbersome. We’ve got over 5 different environments (local, dev, test, uat, and prod) and we need to inject environment-specific classes elsewhere in our code, so this approach is definitely not ideal. Are there any alternatives? Examples would be appreciated, thank you!

//from resources.groovy
beans = {
    switch(Environment.current) {

    case Environment.PRODUCTION:
        cacheBean(com.util.OracleCacheImpl) {
           //properties here            
        }
        break

    case Environment.LOCAL:
        cacheBean(com.util.MockMapCache) { 
           //properties 
        } 
        break 
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T09:43:13+00:00Added an answer on May 27, 2026 at 9:43 am

    You could try setting your bean definitions in Config.groovy, using its built in environments {} handling, and assigning the definitions via the application property.

    So in resources.groovy:

    beans = {
        // Create a clone of the properties definition Closure
        def cacheProps = application.config.cache.bean.props.clone()
        cacheProps.delegate = this
        cacheBean(application.config.cache.bean.class, cacheProps)
    }
    

    And in Config.groovy:

    environments {
        production {
            cache.bean.class = com.util.OracleCacheImpl
            cache.bean.props = {
                //properties as in resources.groovy
            }
        }
        'local' {
            cache.bean.class = com.util.MockMapCache
            cache.bean.props = {
                //properties as in resources.groovy
            }
        }
        'uat' {
            //etc...
        }
        //etc...
    }
    

    Thinking a little longer on it, you could probably put the whole bean definition in a Config.groovy Closure and call it in resources.groovy

    resources.groovy

    beans = {
        // Create a clone of the properties definition Closure
        def cacheBeans = application.config.cache.beans.clone()
        cacheBeans.delegate = this
        cacheBeans()
    }
    

    Config.groovy

    environments {
        production {
            cache.beans = {
                cacheBean(com.util.OracleCacheImpl) {
                    //properties here            
                }
            }
        }
        'local' {
            cache.beans = {
                cacheBean(com.util.MockMapCache) {
                    //properties here            
                }
            }
        }
        'uat' {
            //etc...
        }
        //etc...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I am trying to render a haml file in a javascript response like so:
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.