-
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
Information providing methods in Caffeine.java are not public #311
Comments
Unfortunately, I think you are going down the wrong path by trying to combine Spring Cache with Internally, Spring Cache only provides the loading function during the Instead of exposing this information, I think you'd be better served using Caffeine directly in your apis. You can use |
Thanks for the reply.
|
I see, interesting. Do you think that's cleaner than using the native APIs directly? A big reason why we don't expose those methods on the builder is to avoid confusion with auto-complete. The builder is an instance, so on completing |
I also wonder if you can always construct a |
I think this is cleaner because this way caching is plugged in a noninvasive way, using standard Spring abstraction. I can later switch to another cache implementation by just changing configuration parameters and configuration code, without touching my business code. |
It sounds like we're both happy. I'll close this without adding new methods to avoid making the builder confusing, and you'll have cleaner code without needing them. Thanks for improving the Spring integration, btw! |
Thanks for taking your time for the explanations. Keep up the good work! |
I am trying to configure multiple caches and use them via Spring cache abstraction.
I found https://github.com/stepio/coffee-boots which helps with configuring multiple caches via spring configuration properties. But it unfortunately does not support LoadingCache. I am extending it to support LoadingCache. It creates a Caffeine instance using the Spring configuration options and I need to decide if I need to create a LoadingCache or not. For that, I need to be able to access refreshes() method.
There is a workaround solution to this: I can parse the Spring configuration again to find out if this cache supposed to be Loading or not but I think it would be better if I could simply access these methods.
Here is what I am trying to do:
protected com.github.benmanes.caffeine.cache.Cache<Object, Object> createNativeCaffeineCache(String name, CacheOperationInvocationContext<?> context) { if (getCacheBuilderSupplier() != null) { Caffeine<Object, Object> caffeine = getCacheBuilderSupplier().apply(name); if (caffeine != null) { if (caffeine.refreshes()) { return caffeine.build(new CacheLoader<Object, Object>() { @Override public Object load(Object key) throws Exception { return context.getMethod().invoke(context.getTarget(), ((SymmetricKey) key).getParams()); } }); } else { return caffeine.build(); } } } return super.createNativeCaffeineCache(name); }
The text was updated successfully, but these errors were encountered: