Getting Java Play framework to cache Ebean entities using memcached
Asked Answered
U

1

19

I am running Java Play framework version v2.6.1 and using Ebean for persistence. My intention is to get bean caching going using play2-memcached plugin.

What have I done so far?

  • installed memcached on localhost and enabled verbose logging.
  • replaced ehcache dependency with cacheApi in libraryDependencies in build.sbt (this, I assume, should remove Ehcache completely).
  • added "com.github.mumoshu" %% "play2-memcached-play26" % "0.9.0", to libraryDependencies in build.sbt
  • added "Spy Repository" at "http://files.couchbase.com/maven2", to resolvers in build.sbt
  • added following entries to application conf:

play.modules.disabled += "play.api.cache.ehcache.EhCacheModule" play.modules.enabled+="com.github.mumoshu.play2.memcached.MemcachedModule" play.cache.defaultCache=default play.cache.bindCaches=["db-cache", "user-cache", "session-cache"] memcached.host="127.0.0.1:11211"

  • took my entity and made it implement Serializable, also added @com.avaje.ebean.annotation.Cache annotation.
  • enabled SQL logging

What works?

  • loading entity with Entity.find.byId(id) results SQL SELECT. Loading it again with different request results no SQL statements.
  • opening browser to localhost:11211 shows errors in syslog -- this is to make sure memcached is running and I can see requests appearing
  • making memory dump I can see that cache related classes from com.github.mumoshu are loaded.

What doesn't work?

  • I expect cached objects to be sent to memcached (on read and/or update). This is not happening - there are no memcached logs related to this. Neither there are any connections to port 11211 if I run netstat -na | grep 11211.

Is there anything I'm missing?

Unbound answered 22/8, 2017 at 17:0 Comment(2)
Have you tried using CacheStrategy annotation instead of the Cache annotation? This talks about the CacheStrategy annotation: ebean-orm.github.io/docs/features/l2caching/using-bean-cacheMinister
@CacheStrategy is renamed to @Cache. github.com/ebean-orm/ebean/issues/684Unbound
R
1

You also need to bind javax.caching.CacheManager. Add

libraryDependencies += jcache

to your build.sbt.

If you are using Guice, you have to add the following for Java annotations as well:

libraryDependencies += "org.jsr107.ri" % "cache-annotations-ri-guice" % "1.0.0"

More information can be found in the "JCache Support" section of the Playframework documentation here.

Roswell answered 20/9, 2017 at 20:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.