Grails Version: 3.0.9
Groovy Version: 2.4.5
JVM Version: 1.8.0_60
I am using Grails caching plugin
http://grails-plugins.imtqy.com/grails-cache/3.0.1/guide/index.html
And I had some methods for caching success, such as:
@Transactional
class EventCategoryService {
@Cacheable('eventCategory')
def findAllSports() {
def sportCategories
log.info('called EventCategoryService.findAllSports')
sportCategories = EventCategory.findAllByParentCategoryName("Sport", [sort: "order"])
}
}
Once the cache is created, I no longer see how "EventCategoryService.findAllSports" appears in subsequent call logs as expected.
However, the plugin states in a section called "Caching controller actions" that "you can also cache responses for web requests using the same annotations."
@Cacheable('eventCategory')
def index(IndexCommand command) {
command.init()
log.info('called frontend:index')
render (view: "index", model: [command: command, distances: distances])
}
, , , "frontend: index", , , .
? , .
, - ?
class IndexCommand {
def searchService
def eventCategoryService
int max
int offset
String search
java.util.Date queryStartDate = new Date()
java.util.Date queryEndDate = new Date().plus(365)
def sportCategories
def results
def benchmark = { closure ->
def start = System.currentTimeMillis()
closure.call()
def now = System.currentTimeMillis()
now - start
}
def init() {
if (!max) max = 6
if (!offset) offset = 0
def duration = benchmark {
results = searchService.advancedSearchWithPagedResults(
max,
offset,
search,
queryStartDate,
queryEndDate)
}
log.info("searchService.advancedSearchWithPagedResults took ${duration} ms" )
duration = benchmark {
sportCategories = eventCategoryService.findAllSports()
}
log.info("EventCategory.findAllByParentCategoryName took ${duration} ms" )
}
}