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?

mindas
  • 26,463
  • 15
  • 97
  • 154
  • Have you tried using CacheStrategy annotation instead of the Cache annotation? This talks about the CacheStrategy annotation: http://ebean-orm.github.io/docs/features/l2caching/using-bean-cache – FrancisA Aug 29 '17 at 20:40
  • `@CacheStrategy` is renamed to `@Cache`. https://github.com/ebean-orm/ebean/issues/684 – mindas Aug 30 '17 at 07:34

1 Answers1

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.

mkurz
  • 2,658
  • 1
  • 23
  • 35