使用 guice 在 playframework 中缓存注释

Cache annotations in playframework with guice

我正在尝试插入 cache-annotations-ri-guice,如前所述 here。 我找到了 description。但它不起作用。 我的测试项目看起来像

public class HomeController extends Controller {

public Result index() {
    return ok(getString("qwe"));
}

@CacheResult
private String getString(String str) {
    Random r = new Random();
    return "HelloWorld " + str + r.nextInt();
}
}

此调用每次 returns 不同的值。

build.sbt:

name := """myann"""
organization := "com.example"

version := "1.0-SNAPSHOT"

lazy val root = (project in file(".")).enablePlugins(PlayJava, PlayNettyServer, LauncherJarPlugin)
  .disablePlugins(PlayAkkaHttpServer)
  .settings(libraryDependencies ++= Seq(
     guice,
    jcache,
    ehcache,
    "org.jsr107.ri" % "cache-annotations-ri-guice" % "1.0.0"
  ))

scalaVersion := "2.12.2"

Module.java:

public class Module extends AbstractModule {

@Override
public void configure() {
    install(new CacheAnnotationsModule());
}
}

我的环境: addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.6.3") sbt.version=0.13.15 如何让它正常工作?

此注释不适用于私有方法。