Pergunta

I have some master tables which are not going to change at all. I want to cache it so it doesn't hit database all the time. I have Domain class

class Country {

   static mapping = {
      table 'country'
      version true
      cache true
      id generator: 'sequence', column: 'country_id',
         params: [sequence: 'seq_country']
   }
}

Now whenever call goes to the controller it should fetch list of all countries from cache. Is that possible?

I saw something like Country.get(id) but I need to fetch all rows from cache and not based on id.

Foi útil?

Solução

This is the perfect use case for the Grails Cache plugin. This way you can cache that list of data, and much more when you decide you need it.

Alternatively, I did blog about (years ago) how to implement your own simple cache using ehcache.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top