-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using play-redis AND ehcache? #138
Comments
I have the same issue and added a new attribute in my application.conf and IF stmt in the bindings. I am going to create a PR to push the code up. |
I'm going to write an example hopefully later today. I haven't tested using both implementations simultaneously but I believe, it should work. |
@KarelCemus I have it working locally and can create a PR or send you the code, whichever you like. I also created a "discovery" method for the cluster to gather the slots. There is an issue with rediscala where dns resolution does not work properly to map out the nodes in the RedisPool when working with AWS. Just let me know. |
I'm not aware of the issue within AWS cluster. Maybe you can create a separate issue/PR for it to open a discussion if you think it should be included in the lib. However, it sounds more like a workaround for the rediscala issue. I'll let you know regarding the ehcache integration, I'll look at it myself at first. Thanks. |
Thanks for the quick reply @KarelCemus and @sfelt-carecloud. If someone can share an example of default Play ehcache and play-redis running in same app that'd be great. I'd be looking to keep the default |
Alright, I created the example and it works as expected, I haven't seen any bug. Though, I have to admit there is incomplete documentation at one point. That needs to be fixed for these cases, I'll do it. ExampleLet's use both EhCache and Redis together. Have EhCache bound to the default APIs and Redis cache bound only to the named instance build.sbtlibraryDependencies += ehcache
libraryDependencies += "com.github.karelcemus" %% "play-redis" % "2.0.1" application.conf# enable redis cache module
play.modules.enabled += "play.api.cache.redis.RedisCacheModule"
play.cache.redis {
# do not bind default unqualified APIs
bind-default: false
# name of the instance in simple configuration,
# i.e., not located under `instances` key
default-cache: "redis"
} Controller Home.scalapackage controllers
import javax.inject._
import scala.concurrent.duration._
import scala.concurrent.{ExecutionContext, Future}
import play.api.cache.AsyncCacheApi
import play.api.mvc._
/**
* This controller creates an `Action` to handle HTTP requests to the
* application's home page.
*/
@Singleton
class Home @Inject()( ehcache: AsyncCacheApi, @Named( "redis" ) redis: AsyncCacheApi, cc: ControllerComponents )( implicit ec: ExecutionContext ) extends AbstractController( cc ) {
def index = Action {
Ok( views.html.index() )
}
val ehImpl = ehcache.getClass.getName
val redisImpl = redis.getClass.getName
def testEhCache( ) = Action.async {
var hit = true
ehcache.getOrElseUpdate( "key", 2.seconds ) {
hit = false
Future successful "value"
}.map { _ =>
Ok( if ( hit ) s"Hit in EhCache ($ehImpl)" else s"Miss on EhCache ($ehImpl). New value computed and stored." )
}
}
def testRedis( ) = Action.async {
var hit = true
redis.getOrElseUpdate( "key", 2.seconds ) {
hit = false
Future successful "value"
}.map { _ =>
Ok( if ( hit ) s"Hit in Redis ($redis)" else s"Miss on Redis ($redis). New value computed and stored." )
}
}
} I hope this answers your question. Even if so, please keep the issue opened to indicate the documentation bug. |
Thanks. I notice a few differences with the |
This is the API provided by Play thus shared by both implementations. There is also another API provided by the |
Hi Karel, may be I have done something wrong I am using play 2.6.2 and my application.conf is like
I am getting error
Guide me to implement named cache also |
Hi, well, it seems you have/want to have several named caches but what which one is the default and bound to the unqualified traits? It's not By the way, Regarding the issue - you are somewhere injecting unqualified SyncCacheApi trait but no one registered its implementation. What instance do you expect there? |
Thanks for the quick reply , Yes I want several named caches , default is the play cache which I have updated as below
so I put bind-default true also , error what I got is like
below is sample of my Implementation class
|
Hmm, you've hit a tricky place I didn't know about (or didn't notice earlier). You are using That is the reason why this does not work but I'm thinking about the compatibility with, e.g., ehcache because use of the different annotation breaks the interchangeability of the implementation. |
Thanks Karel , truly appreciate your contribution towards community !! |
I'm glad it helped. I'm probably gonna deprecate |
@KarelCemus , Is there any way to override the implementation of |
Well, that's not much common requirement so it is not directly supported by play-redis. The binding is quite hard-coded in the module. Right now, I see only two ways:
Does this answer your question? |
Hey all, I started a new project with play-redis samples. Could you review them and give me some feedback if something is missing or there is anything else you'd appreciate? Thanks |
I'm closing the issue
If there is still anything unaddressed, please, let me know |
@KarelCemus , Definitely I would like to be part of new project . It is good if we can provide dynamic prefix provider also for named cache . |
@ImportSumit Open a new issue, please, and propose how it should work. I'm not sure how to tailor the prefixed considering the prefix might be request-specific, user-specific, etc., i.e., context-specific. The question is how to access the context in the prefixer. I'm not sure that the context-unaware prefixer is worth implementing as there is not much added value. |
Hi @KarelCemus, I'm new with Play, and I need exactly this, Ehcache and Redis cache working togheter. You has mentioned about an example that uses this approach, but I wasn't able to find it, at least not for Java. Could you please let me know where that is? Thank you so much! |
Hi @KarelCemus, following the Scala sample was very easy to transport it into Java code, I have the full integration working without any issues at the moment. |
This isn't an issue, but a question. Is it possible to use both ehcache and play-redis? I was goofed around with the configuration for a bit, but was never able to make play-redis and ehcache run together. A subset of what I had configured is as follows.
I have a file called
redis.conf
:In
application.conf
I've enabled the module as follows:play.modules.enabled += "play.api.cache.redis.RedisCacheModule"
The problem is when I try to inject an instance of
CacheAsyncApi
I get an error indicatingNo implementation for play.api.cache.redis.CacheAsyncApi was bound.
. Presumably this is doe to thebind-default = false
statement? If I remove that I get various other issues related to having to define theplay
cache, which is the default as mentioned in the docs.Is there an example anywhere of running both caches?
The text was updated successfully, but these errors were encountered: