问题
We are trying to follow the "Caching in templates" example listed in http://www.playframework.com/documentation/2.1.1/JavaCache and the compiler throws us an "not enough arguments for method getOrElse
" exception message.
Our code in the template:
@play.cache.Cache.getOrElse("cached-content", 3600){
test
}
So we decided to dig the API and apparently we still short of java.util.concurrent.Callable
parameter. Does anyone know what should we pass in for that parameter?
Thanks
Play 2.1.1 Javadoc
回答1:
it's because you are trying to use a Java API from a Scala template with the syntaxe of the Scala cache API. If you want to use the example from the documentation you need to write something like :
@import play.api.Play.current
@play.api.cache.Cache.getOrElse("key", 3600) {
<h1>Cached content</h1>
}
the play.api package is the package for Scala APIs.
If you want to use the Java Cache API from a template, this API takes 3 parameters and you need to write something like :
@play.cache.Cache.getOrElse("key", new java.util.concurrent.Callable[String] {
def call: String = "Cached content again"
}, 3600)
来源:https://stackoverflow.com/questions/16455474/how-do-we-call-caching-in-template-for-play-2-1