Reputation: 9724
I've just started using Redis
in my Play application and it works greatly. Looking at some examples I've found in the Internet, I'm wondering what's the difference between the following two code snippets:
import redis.clients.jedis._
import com.typesafe.plugin.RedisPlugin
import play.cache.Cache
val pool = app.plugin(RedisPlugin.class).jedisPool
val jedis = pool.getResource
jedis.set("myKey", "myValue")
pool.returnResource(jedis)
...
val myValue = jedis.get("myKey")
... and this one:
import com.typesafe.plugin.RedisPlugin
import play.cache.Cache
Cache.set("myKey", "myValue")
...
val myValue = Cache.get("myKey")
OK, the final result is the same, i.e. I'm retrieving a value from the cache... but when should I use a JedisPool
instead of a simple Cache.get
?
Tx.
Upvotes: 1
Views: 624
Reputation: 1769
You would have to look at the plugin code to check implementation of the Redis Cache in your second option to tell the difference.
Using the Play Cache is just slightly more abstracted from the implementation. I would recommend it if you could change your cache in the future. On the opposite, if you would like to use this code in another environment than Play!, you should prefer the first option.
Upvotes: 1