-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add CaffeineSpec (like Guava's CacheBuilderSpec) #37
Comments
Sure, that's a good idea to add to the wiki page. If you take a look at Copier and its associated implementation then you should have an idea of what is involved. I'll try to add an example this evening (PST time). I generally don't recommend JCache because I think it has numerous flaws. If you're using it for Spring, native support is planned. |
Oh, and why do you need a custom serializer? That is only for store-by-value which copies entries entering and leaving the cache. The main use is for distributed caches and store-by-reference is the more appropriate (and default) behavior. So perhaps first we should understand why |
Thanks for the info. TBH, I'm not a fan of JCache either. My current apps. uses spring cache annotations with Guava and I'm quite happy. And hearing that caffeine is nearly 10X faster than Guava, thats really nice to have. Hearing future native support is awesome. I suggest I can implement one easily to try. PS: I'd be good to add this to spring-boot also. and some config. for specs directly from config file. like Guava impl. |
Seems to be planned as part of Spring Boot 1.4. I haven't used Spring since 2.0 so sorry if I'm a little behind on things. :) Can you use the Guava adapter with Spring's Guava cache extension? Then when 1.4 is out you can switch over and remove the indirection. I assume that is easier than adding JCache? I didn't know anyone outside of Google used |
Yep, I think I can use it, it'll be much more simpler :) I have a certain app. that I want to test it to see the performance gain.. CacheBuilderSpec is like configuring your caches, eviction time, cache size etc, without any line of code :) While using spring-boot, these king of stuff is useful. If you need different specs for different caches, than you need to implement it anyway. Than one can use Java based builder. Of course, another option which I believe could be useful also, they can put a param. for config. file if jcache config file also applies to caffeine, than users can modify this file. And with this, each cache can be configured separately. |
JCache has a lot special configuration aspects so unfortunately that can't be shared. I also like the library over framework approach, so I prefer leaving external files to let frameworks (like Spring) decide what integration should look like. I'm hopeful that I won't need to provide a config and cache managers, and can instead provide the hooks like we did with Guava. So I'm going to rename this task to be about adding a |
Stéphane Nicoll indicated on the Spring task that a |
Thats perfect. Thanks for the update.. |
Spring Boot #4903 provides integration. Now I understand why a |
I was looking to migrate and didn't find the CacheBuilderSpec as in guava so I stumbled onto this ticket. But reading all this it looks like the fix in Spring Boot doesn't seem like a proper equivalent to the Caffeine.newBuilder().from("maximumSize=100,expireAfterAccess=1h") syntax that is easier to get from a configuration file of some sort. Furthermore the Spec class seems trival enough to add, unless I haven't had enough coffee yet ;) |
Are you using Spring? If so then it sounds like you want to externalize the configuration parameters? The Spring Boot integration seems to imply that Java configuration is their new preference. If you're not using Spring, can you describe how you are configuring your app? For example, what file format are you using? Is this needed for any other popular frameworks or internal conventions? Is this desirable for a Guava bridge (
If a Feel free to reopen or start a new ticket. |
Yes I'm using spring and I like my caching configuration outside my application. This way if I see that I'm running low on memory I can still squeeze out a bit if I'm really in trouble. Or just the opposite. While testing I can see how certain options work out for the better or for worse... |
Sounds reasonable. I'll take a look at offering a port of |
No, I was already considering adding it myself via a basic split & set approach. Nothing really fancy. |
As the original poster for this request, i would like to add something as well. After reading response from spring team, i realized that they are right. Currently, spring-boot support multiple caching solutions. And to configure each of them, you need their own config file. And spring boot gives you a property that u can show your config file. If not found, it uses tje library default specs. For guava, there is no config file but a config string. If caffeine already has a config file, it could be used, there is no need to add yet another config. If not, instead of guava spec, something more powefull, a json based conf. File that can configure each cache seperately would be usefull. |
I really appreciate the feedback, @gokhanoner. A Guava-like spec is as far as I'd go for the core module. I'd like to keep it as a library, whereas a configuration file leads to cache managers, numerous dependencies, and an opinionated framework mindset. That is best left to integration frameworks (e.g. JEE, Spring, Dropwizard, Play, Grails) which each have their own file formats, life cycles, etc. I will provide integration modules when helpful like JCache for the JEE world, which in that case didn't have a format convention. Perhaps XML is the JEE norm due to legacy, but because there wasn't a expectation I used Typesafe Config (a powerful and friendly json dialect). Unfortunately JCache is a highly flawed standard (even the RI is warned to not be used in production), so applications have been very slow to adopt. When I used Spring in the 2.x days its convention was to use property files with EL in the XML wiring. I'm a little surprised that Spring didn't expand I think being a library but trying to work with framework authors to make integration as painlessly as possible is the best choice. The idea of a |
Similar to Guava's CacheBuilderSpec, the CaffeineSpec simplifies the creation of a builder from externalized flags. This can be useful for configuration files, such as Spring properties. The string format and options are the same as Guava's, except that `concurrencyLevel` is not supported. The `disableCaching` factory method was not ported over since its usefulness seemed questionable. CaffeineSpec passes Guava's test cases, with the above changes made.
2.1.0 is now released with CaffeineSpec. Thanks again for the feedback. |
@gokhanoner @koen-serry |
Oh, Spring Boot 1.4-M2 is already out. That's the version that added Caffeine support. |
Yep, and ive already give it a try ;)
|
can u give some examples about the strategy for config file. You refer to https://github.com/eishay/jvm-serializers/wiki for 3rd party serializers.
For example, if we use Protobuff/Protostuff etc. which classes we can use ? Or do we need to implement something ?
Any example would be good.
The text was updated successfully, but these errors were encountered: