我们如何称呼“模板缓存"?适用于Play 2.1? [英] How do we call "Caching in Template" for Play 2.1?
问题描述
我们正在尝试遵循 http://中列出的模板缓存"示例www.playframework.com/documentation/2.1.1/JavaCache ,编译器向我们抛出"not enough arguments for method getOrElse
"异常消息.
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.
模板中的代码:
@play.cache.Cache.getOrElse("cached-content", 3600){
test
}
因此,我们决定对API进行挖掘,显然我们仍然缺少java.util.concurrent.Callable
参数.有人知道我们应该为该参数传递什么吗?
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?
谢谢
推荐答案
这是因为您试图使用Scala缓存API的语法从Scala模板中使用Java API.如果要使用文档中的示例,则需要编写如下内容:
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>
}
play.api软件包是Scala API的软件包.
the play.api package is the package for Scala APIs.
如果您想通过模板使用Java Cache API,则此API需要3个参数,您需要编写类似以下内容的>
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)
这篇关于我们如何称呼“模板缓存"?适用于Play 2.1?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!