Playframework 播放2.4 cacheApi(EhCache)在重新加载激活器后从磁盘获取缓存值
在Play 2.4中,当我将对象添加到缓存(磁盘持久化)并尝试读取所有内容时,我遇到了EhCache问题。但当我通过更改配置或代码导致播放重新加载时。无法读取值 github项目的链接 控制器代码:Playframework 播放2.4 cacheApi(EhCache)在重新加载激活器后从磁盘获取缓存值,playframework,ehcache,Playframework,Ehcache,在Play 2.4中,当我将对象添加到缓存(磁盘持久化)并尝试读取所有内容时,我遇到了EhCache问题。但当我通过更改配置或代码导致播放重新加载时。无法读取值 github项目的链接 控制器代码: class CacheController @Inject()(cacheApi: CacheApi) extends Controller { implicit val vFormat = Json.format[ValueObject] implicit val rFormat = Js
class CacheController @Inject()(cacheApi: CacheApi) extends Controller {
implicit val vFormat = Json.format[ValueObject]
implicit val rFormat = Json.format[Response]
val key = "key"
val valueToTest = ValueObject("test1", "test2")
def value(): Action[AnyContent] = Action.async {
Future {
val withCast = cacheApi.get[ValueObject](key)
val withoutCast = cacheApi.get(key).toString
Ok(Json.toJson(Response(withCast, withoutCast)))
}
}
def setValue(): Action[AnyContent] = Action.async {
Future {
cacheApi.set(key, valueToTest)
Ok("value set")
}
}
}
// value object to store in cache
case class ValueObject(field1: String, field2: String)
// object for response
case class Response(withCast: Option[ValueObject], withoutCast: String)
复制步骤:
1.通过打开将某些内容添加到缓存
2.通过打开的结果从缓存中获取上一个对象是=>{“withCast”:{“field1”:“test1”,“field2”:“test2”},“withoutCast”:“Some(ValueObject(test1,test2))”}
3.更改代码或配置中的某些内容以导致播放重新加载
4.再次打开从磁盘读取缓存对象,结果是=>{“withoutCast”:“Some(ValueObject(test1,test2))”}您的Ehcache配置是什么样子的?您的配置不应该像中那样具有持久性元素吗?我认为这是重新启动应用程序时的预期行为。