我们的应用程序基于Play 2.4与Scala 2.11和Akka构建.使用的数据库是MySQL.
缓存在我们的应用程序中大量使用.我们使用Play的默认EhCache进行缓存.
我们的示例代码段:
import play.api.Play.current
import play.api.cache.Cache
case class Sample(var id: Option[String],
//.. other fields
)
class SampleTable(tag: Tag)
extends Table[Sample](tag, "SAMPLE") {
def id = column[Option[String]]("id", O.PrimaryKey)
// .. other field defs
}
object SampleDAO extends TableQuery(new SampleTable(_)) with SQLWrapper {
def get(id: String) : Future[Sample] = {
val cacheKey = // our code to generate a unique cache key
Cache.getOrElse[Future[[Sample]](cacheKey) {
db.run(this.filter(_.id === id).result.headOption)
}
}
}
Run Code Online (Sandbox Code Playgroud)
我们使用Play的内置Specs2进行测试. …
我的应用程序使用Play 2.4和Scala 2.11.我开始转换现有代码以使用Play 2.4附带的Google Guice.
当我在进行第一组更改后运行代码时,我发现代码中的某些DAO失败并出现循环依赖性错误.
例如,我有两个DAO
class BookDAO @Inject()
(protected val personDAO : PersonDAO,
@NamedDatabase("mysql")protected val dbConfigProvider: DatabaseConfigProvider) extends HasDatabaseConfigProvider[JdbcProfile] {
...
...
val personId = //some id
personDAO.get(personId)
}
class PersonDAO @Inject()
(protected val bookDAO : BookDAO,
@NamedDatabase("mysql")protected val dbConfigProvider: DatabaseConfigProvider) extends HasDatabaseConfigProvider[JdbcProfile] {
...
...
val bookName= //some id
personDAO.getByName(bookName)
}
Run Code Online (Sandbox Code Playgroud)
尝试访问BookDAO或PersonDAO时出现以下错误
Tried proxying schema.BookDAO to support a circular dependency, but it is not an interface.
at schema.BookDAO.class(Books.scala:52)
while locating schema.BookDAO
Run Code Online (Sandbox Code Playgroud)
有人可以帮我解决这个错误. …