Sunday 15 July 2012

caching - Grails Cache and EHCache Plugin caches Controller methods but not Service methods -



caching - Grails Cache and EHCache Plugin caches Controller methods but not Service methods -

i'm having problem getting grails ehcache plugin cache service methods. here setup:

grails 2.4.2, jdk 1.7

buildconfig.groovy compile ":cache-ehcache:1.0.4"

config.groovy defines next cache named "cache"

grails.cache.config = { cache { name 'cache' timetoliveseconds 60 } }

the next controller method caches. have tested setting breakpoint in method, , nail first time, until cache expires.

@cacheable('cache') def index() { render "index-$params.id" }

i can check keys in cache with:

grailscachemanager.getcache('cache').getnativecache().getkeys()

and see value:

localhost:get:/grails-cache-test/cache/index?id=34

so far good.

the next service method exists:

@cacheable('cache') public method1(id) { "method1+$id" }

i set break point in here, , method called, regardless of @cacheable annotation. i've tried setting value , key annotation attributes manually, , no change. test calling method non-cached controller method, straight console plugin. when keys in service method see there no keys set.

i've looked through examples in official documentation, code samples online, github, book have, looks good, i'm not sure problem lies.

any ideas on why service method not cache value? thanks!

update 1

i've been digging grails cache-1.1.8 plugin (as associated cache-ehcache-1.0.4 plugin), , believe i've found helpful. in pagefragmentcachingfilter.dofilter() there calls check controller's annotations - nil check service. appears result, service annotations never honored. there lot of documentation mentions service methods, don't know if there elsewhere handles this, or if it's less mutual utilize case compared controller methods.

update 2

it appears controllers , services handled separately. in cacheaspectsupport.execute() there for() loop phone call cacheputrequest.apply(result.get());, add together entry cache. unfortunately after entry added request, not available retrieved. underlying put() code part of spring source, @ point i'm not sure if it's grails plugin issue or spring source issue.

i have created jira issue plugin gpcacheehcache-16

grails caching plugins ehcache grails-2.0

No comments:

Post a Comment