문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top