score:0

Try the JedisPool. the implementation of redis.

You need to disable the default cache module before using the redis cache. play.modules.disabled = ["play.api.cache.EhCacheModule"]

In the build.sbt.

"com.typesafe.play.modules" %% "play-modules-redis" % "2.4.0",

score:0

You can use the cache in any class of your project, I used the following code in my java project:

public class ProductServiceImpl implements ProductService {

    private final WSClient ws;
    private UserService userService;
    private CacheApi cache;

    @Inject
    public ProductServiceImpl(WSClient ws) {
        this.ws = ws;
    }

    @Inject
    public void setCache(CacheApi cache) {
        this.cache = cache;
    }

    @Inject
    public void setUserService(UserService userService) {
        this.userService = userService;
    }

}

But in Scala I assume that you can do something like this:

import javax.inject._
import play.api.cache._

class Model @Inject() (cache: CacheApi) {
  // ...
}

Note:

The @Inject annotation can be used on fields or on constructors

More info about how to use the @Inject annotation on play scala: https://www.playframework.com/documentation/2.4.x/ScalaDependencyInjection#Declaring-dependencies


Related Query

More Query from same tag