Say I have a class Person
with a name
field. I can do a Person.findByName
but what if I want to override this method to ensure that the query is cached? How do I override this dynamic finder method?
Asked
Active
Viewed 371 times
3

Shashank Agrawal
- 25,161
- 11
- 89
- 121

Champ
- 1,291
- 4
- 16
- 32
-
1Don't. Use a service and cache the method on the service. That's the correct way to implement this pattern. – Joshua Moore Jan 06 '15 at 11:04
-
@JoshuaMoore Should it be equivalent if I have Person.forName that does the same thing as you suggested to do on the service? – Champ Jan 06 '15 at 11:05
-
You can implement static method in domain class. – Andriy Budzinskyy Jan 06 '15 at 13:46
1 Answers
2
You can simply write:
Person.findByName("some-name", [cache: true])

Shashank Agrawal
- 25,161
- 11
- 89
- 121
-
Yes, I am aware of that. But what I want is to change 'Person.findByName("some-name")' so that it is cacheable query by default. Don't want a coder to remember to add ', [cache: true]' wherever the dynamic finder is used. – Champ Feb 05 '15 at 05:53