[英]Getting Java Play framework to cache Ebean entities using memcached
I am running Java Play framework version v2.6.1 and using Ebean for persistence. 我正在运行Java Play框架版本v2.6.1并使用Ebean进行持久化。 My intention is to get bean caching going using play2-memcached plugin. 我的目的是使用play2-memcached插件获取bean缓存 。
What have I done so far? 到目前为止我做了什么?
memcached
on localhost and enabled verbose logging. 在localhost上安装了memcached
并启用了详细日志记录。 ehcache
dependency with cacheApi
in libraryDependencies
in build.sbt
(this, I assume, should remove Ehcache completely). 用cacheApi
中的libraryDependencies
中的build.sbt
替换了ehcache
依赖(我假设,应该完全删除Ehcache)。 "com.github.mumoshu" %% "play2-memcached-play26" % "0.9.0",
to libraryDependencies
in build.sbt
将"com.github.mumoshu" %% "play2-memcached-play26" % "0.9.0",
到libraryDependencies
中的build.sbt
"Spy Repository" at "http://files.couchbase.com/maven2",
to resolvers
in build.sbt
将"Spy Repository" at "http://files.couchbase.com/maven2",
添加"Spy Repository" at "http://files.couchbase.com/maven2",
到build.sbt
resolvers
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"
Serializable
, also added @com.avaje.ebean.annotation.Cache
annotation. 拿了我的实体并使它实现了Serializable
,还添加了@com.avaje.ebean.annotation.Cache
注释。 What works? 什么有用?
Entity.find.byId(id)
results SQL SELECT
. 使用Entity.find.byId(id)
加载实体会导致SQL SELECT
。 Loading it again with different request results no SQL statements. 使用不同的请求结果再次加载它没有SQL语句。 com.github.mumoshu
are loaded. 进行内存转储我可以看到com.github.mumoshu
中的缓存相关类已加载。 What doesn't work? 什么不起作用?
netstat -na | grep 11211
如果我运行netstat -na | grep 11211
则没有任何与端口11211的连接 netstat -na | grep 11211
. netstat -na | grep 11211
。 Is there anything I'm missing? 有什么我想念的吗?
You also need to bind javax.caching.CacheManager
. 您还需要绑定javax.caching.CacheManager
。 Add 加
libraryDependencies += jcache
to your build.sbt
. 到你的build.sbt
。
If you are using Guice, you have to add the following for Java annotations as well: 如果您使用的是Guice,则还必须为Java注释添加以下内容:
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 . 更多信息,请Playframework文档“的JCache支持”一节中找到这里 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.