-
Notifications
You must be signed in to change notification settings - Fork 45
Named cache #114
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
Named cache #114
Conversation
f2a612d
to
06be74c
Compare
Hey, sure. I'm going to review reference.conf tomorrow and I'll take a deeper look on the other files during the weekend. I'm short with time earlier. |
Great, thanks! No rush. And please ignore tests, they are about to be fully rewritten. And the module and the components are now also stable, I merged their update. |
src/main/resources/reference.conf
Outdated
# | ||
# for more details see https://www.playframework.com/documentation/2.6.x/ScalaCache#Accessing-different-caches | ||
# | ||
instance { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would make it instances
src/main/resources/reference.conf
Outdated
instance { | ||
|
||
# definition of the default cache, | ||
# its name is defined in 'play.cache.defaultCache' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
play.cache.redis.default-cache
is defined below, but play.cache.defaultCache
is mentioned here
Thank you @checat for your feedback, it's fixed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Some really minor feedback, but nothing that should hold up the PR IMO.
Appreciate the quick turnaround on this work; some excellent customer service! 😀
src/main/resources/reference.conf
Outdated
# definition of the default cache, | ||
# its name is defined in 'play.cache.default-cache' | ||
# | ||
# when there should be more caches, defined them all under the 'instance' key. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very minor point, there are some places in the comments that still reference instance
instead of the updated instances
.
src/main/resources/reference.conf
Outdated
# | ||
# note: this is global definition, can be locally overriden for each | ||
# cache instance. To do so, redefine this property | ||
# under 'play.cache.redis.instance.instance-name.this-property'. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here too.
src/main/resources/reference.conf
Outdated
# | ||
# note: this is global definition, can be locally overriden for each | ||
# cache instance. To do so, redefine this property | ||
# under 'play.cache.redis.instance.instance-name.this-property'. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And here.
@rval Thanks for your feedback, I'm sorry for my sloppiness. It should be fixed. I'll wait couple more days for the last feedback and then merge the PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, I looked through the code and it looks very good. I'm pretty impressed by the change set. The only one think to fix IMO is the default DB.
src/main/resources/reference.conf
Outdated
# redis server: port | ||
port: 6379 | ||
# redis server: database number | ||
database: 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: database indexes start from 0, which is default to be connected when you use redis-cli
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realize that it may break some people's usage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly, I don't mind that much for backward compatibility right now as there is none right now. The change is too big to keep it compatible I think.
But on the other hand, the complexity of the new configuration is worrying me, as I posted couple secs ago.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. That's the right point of time to make any breaks.
@pcejrowski Thanks for your feedback. I am worried about the complexity of the configuration. I hoped for simpler settings but it conflicts with the need for expressing complex setups. I mean that small apps with just single redis cache will have quite complex settings I think (comparing to version 1.x). Do you have any ideas to improve the situation or do you think it is alright to keep it this way? |
True. |
That's true, basically, I wanted to do it at the beginning. But then there raised two questions:
I concluded that it would make the things much more difficult to understand instead of easing the use. What do you think? |
Just realized |
Yes, right. I don't like it but didn't figure out any other way to overcome the limitations I mentioned and support multiple types of setup. But still, it is very complex for the simple situations. Consider this:
I think this is the most simple use case but I very dislike the key, it does not seem intuitive at first. |
Another possible solution I can think of is as follows: for single server:
for cluster
with providing named-cache: false, which simplifies 99% of use-cases, right? (Named cache was requested after a long time of successful usage of |
So basically you propose another " By default, when I think that might work and would not complicate either the comprehension or the implementation as it is basically just projection. Furthermore, as I proposed the settings a bit "recursively", it works smoothly with that. In the case of Furthermore, in 99% cases, the migration would be quite simple I believe. I am surprised it didn't occur to me earlier, it is quite obvious and elegant. I really like it, thanks! |
Exactly. I tried to think of it right now and it seems, that with those two flags you cover all the specificities. |
Well, personally, I use it in a very simple scenario, so I'm not aware of all possibilities of the redis. But I cannot think of anything I know what would not be supported by these two switches. It supports standalone/cluster/cloud as well as single cache/multiple named caches. I can imagine introduction of other values of |
Apologies for the late response. I think both options work well, but I have a slight preference for the original I assume this new release will break backwards compatibility one way or another given the other changes planned. I think most integrators would accept some minor work to get on the latest release with its improvements, particularly if those are documented in Another thought—if play.cache.redis {
instances {
default: { # No need for default-cache since this is the default.
host: "some.host",
port: 1234
},
session-cache: {
host: "some.other.host",
port: 4321
}
}
} Like I said, just personal preference. Either approach works for me. |
If two named caches were configured to point to the same Redis host, port, and database, then it would be possible to have key collision. Is it possible to add an option for named cache to implicitly prepend the namespace to the key? akin to play2-memcached |
@rval
This seems quite minor to me, assuming namespace is small.
I am suggesting to add namespace as an option, which can be enabled/disabled for each named cache. We are still able to configure and tune individual cache as needed. Namespace works quite naturally with named cache since the "name" of the cache itself is the namespace. The different options to avoid key collision are:
I would argue that 4 is quite a reasonable option. |
Hi guys, thanks for your contribution. @johnsiu I created a new ticket #118 for this discussion to keep this thread focused.
Well it depends, I think not everybody is familiar with named caches so force them to "know them" does not seem right, though the configuration is still simple. I think it might be intimidating for new users and could increase the initial barrier. Thus lowering it by keeping the default config simple in 95% cases seems right.
That's true, but I think it will break only configuration compatibility. Otherwise, it should be source compatible for regular users (not those who somehow extend or modify the core).
I agree.
Well, it occurred to me too, but I decided to remain consistent with Play, which uses |
@KarelCemus all your counterpoints are totally reasonable. Like I said, just my own personal preference, certainly not a deal breaker. Please let me know if there's anything I can do to help. |
@rval Thanks for your feedback, really appreciate it. Unfortunately, I must apologize for this pending PR, I have really busy 3 weeks and had no time to deal with this. One week left and it should be better again. Then I'm about to complete this PR. I have a pretty clear vision how to finish it. Thanks for your patience. |
The value should have a `-` prefix
…tion mechanisms - advanced examples and description in reference.conf - implemented a fallback cache manager
This PR redesigns configuration to fully implement named caches. Fixes #106.
This is intended for version 2.x.x without backward compatibility of the configuration. There will be warnings and migration guide to allow more advanced usage.
@pcejrowski @rval May I ask you to review this PR, especially the
reference.conf
file? It should be final and stable. Modules and Components will change for sure, some other binding-related classes might change too but the configuration proposal is final.