Skip to content
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

Closed
gokhanoner opened this issue Dec 9, 2015 · 20 comments
Closed

Add CaffeineSpec (like Guava's CacheBuilderSpec) #37

gokhanoner opened this issue Dec 9, 2015 · 20 comments

Comments

@gokhanoner
Copy link

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.

@gokhanoner gokhanoner changed the title custom strategy example custom jcache strategy example Dec 9, 2015
@ben-manes
Copy link
Owner

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.

@ben-manes
Copy link
Owner

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 store-by-value is a good use-case.

@gokhanoner
Copy link
Author

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.

http://docs.spring.io/spring-boot/docs/1.3.0.M1/reference/htmlsingle/#boot-features-caching-provider-guava

@ben-manes
Copy link
Owner

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 CacheBuilderSpec! It was really useful for the internal flags, never noticed anyone using it otherwise. If it will simplify Spring integration then its worth adding.

@gokhanoner
Copy link
Author

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.

@ben-manes
Copy link
Owner

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 CaffeineSpec and supporting CacheBuilderSpec in the Guava module.

@ben-manes ben-manes changed the title custom jcache strategy example Add CaffeineSpec (like Guava's CacheBuilderSpec) Dec 10, 2015
@ben-manes
Copy link
Owner

Stéphane Nicoll indicated on the Spring task that a CaffeineSpec shouldn't be necessary and that he'll take care of doing it the right way for Boot. I'm eager to see what looks like, but leaving this open in case there's a misunderstanding and a spec is useful. If it doesn't aid Spring's integration then I'll close this until another user reopens for discussing their need.

@gokhanoner
Copy link
Author

Thats perfect. Thanks for the update..

@ben-manes
Copy link
Owner

Spring Boot #4903 provides integration. Now I understand why a CacheBuilderSpec wouldn't have been helpful to the integration, so I'm closing this.

@koen-serry
Copy link

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 ;)

@ben-manes
Copy link
Owner

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 (guava adapters) or general library use?

CacheBuilderSpec was primarily for Google's internal Flag library so the single line CSV style made sense given how flags are parsed. I'd imagine most users would want the configuration broken into multiple entries and have to perform some munging between their format and the spec's. For example with TypesafeConfig (json-like) would require iterating over the sub paths, converting snake to camel case, and joining the strings. A spec would still be useful, but some custom code required.

If a CaffeineSpec is useful than I agree it should be added. Since it seemed to not be of interest to the Spring guys and originally for Google's internal use, I hadn't bothered.

Feel free to reopen or start a new ticket.

@koen-serry
Copy link

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...

@ben-manes
Copy link
Owner

Sounds reasonable. I'll take a look at offering a port of CacheBuilderSpec. Are there any aspects of Guava's spec that you'd want changed / reconsidered?

@ben-manes ben-manes reopened this Jan 14, 2016
@koen-serry
Copy link

No, I was already considering adding it myself via a basic split & set approach. Nothing really fancy.

@gokhanoner
Copy link
Author

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.

@ben-manes
Copy link
Owner

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 CacheBuilderSpec into a set of properties, which are then joined to feed into the spec. Perhaps by offering a spec they'll decide to offer that as an option, or a Spring module could be provided as an aid.

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 CaffeineSpec has merit and helps in that goal, so I hope to flush that out shortly.

ben-manes added a commit that referenced this issue Jan 18, 2016
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.
@ben-manes
Copy link
Owner

2.1.0 is now released with CaffeineSpec. Thanks again for the feedback.

@ben-manes
Copy link
Owner

@gokhanoner @koen-serry
Spring 4.3-RC1 was released. I assume the next Spring Boot RC will follow shortly. These have Caffeine (with CaffeineSpec) integration for Spring Cache. Hope that helps.

@ben-manes
Copy link
Owner

Oh, Spring Boot 1.4-M2 is already out. That's the version that added Caffeine support.

@gokhanoner
Copy link
Author

Yep, and ive already give it a try ;)
On 6 Apr 2016 8:31 p.m., "Ben Manes" [email protected] wrote:

Oh, Spring Boot 1.4-M2 is already out. That's the version that added
Caffeine support.


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#37 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants