stepio / coffee-boots Goto Github PK
View Code? Open in Web Editor NEWSupport property-based configuring of multiple Caffeine caches for Spring Cache abstraction.
License: Apache License 2.0
Support property-based configuring of multiple Caffeine caches for Spring Cache abstraction.
License: Apache License 2.0
I have @EnableCaching
on my application class.
In application.properties I have:
# caching
coffee-boots.cache.spec.reCountries=expireAfterWrite=3d,expireAfterAccess=1d,maximumSize=500
coffee-boots.cache.spec.reInstalledCountries=expireAfterWrite=3d,expiresAfterAccess=1d,maximumSize=500
But when I try to run a test or boot my application I get:
java.lang.IllegalStateException: No CacheResolver specified, and no bean of type CacheManager found. Register a CacheManager bean or remove the @EnableCaching annotation from your configuration.
If I add a bean with a CacheManager:
@Bean
public CacheManager cacheManager() {
return new MultiConfigurationCacheManager();
}
My application runs but it doesn't look like my cache is configured per the .properties file:
@Autowired
CacheManager cacheManager
...
cacheManager.getCache("reCountries")
gives me:
result = {org.springframework.cache.caffeine.CaffeineCache@20802}
allowNullValues = true
cache = {com.github.benmanes.caffeine.cache.UnboundedLocalCache$UnboundedLocalManualCache@20804}
cache = {com.github.benmanes.caffeine.cache.UnboundedLocalCache@20807} size = 1
policy = null
name = "reCountries"
Do I need to provide a CacheManager bean or does coffee-boots do that for me already? If it does, what am I doing wrong that causes the error I'm getting?
I understand I can try this out by myself, but in the readme.md document, can you please clarify how exactly this works in concert with Spring Boot? E.g. when you say:
coffee-boots.cache.spec.myCache=maximumSize=100000,expireAfterWrite=1m
Is that "in addition to" spring boot's:
spring.cache.type=caffeine
spring.cache.cache-names=myCache,cache2,cache3
spring.cache.caffeine.spec=maximumSize=500,expireAfterAccess=600s
Or, does the coffee-boots.* properties completely replace spring.cache.* properties?
I hope it is in addition and not replacement. i.e. If I use "cache2" or "cache3" in my class annotation, I get the default/global spring configuration values (500 maxSize in this case); if I use "myCache" in my annotation, I get coffee-boot values (10000 maxSize). If it doesn't work that way, I'd like to request that it does.
Thanks!
The project could not be analyzed because of build errors. Please review the error messages here. Another build will be scheduled within 24 hours. If the build is successful this issue will be closed, otherwise the error message will be updated.
This is an automated GitHub Issue created by Sonatype DepShield. GitHub Apps, including DepShield, can be managed from the Developer settings of the repository administrators.
When i add refreshAfterWrite option.
i received java.lang.IllegalStateException: refreshAfterWrite requires a LoadingCache
pls how to i use refreshAfterWrite ?
Spring Boot has spring.cache.type=NONE
to disable caching altogether, e.g. for a development profile; see Spring Boot - How to disable @Cacheable during development?.
How can I disable Coffee Boots in a similar manner via the Spring Boot application configuration?
Add @Conditional({ CacheCondition.class })
to CaffeineSpecAutoConfiguration
, similar as Spring Boot's CaffeineCacheConfiguration
has this as well.
In this case the coffee-boots
auto-configuration will not kick in if spring.cache.type
property is not set to caffeine
. This is useful with different cache implementation per environment.
Please install our new product, Sonatype Lift with advanced features
Hi,
Can you please provide a version of coffee boots which is based on Spring Boot 3? This would be very helpful.
Thanks.
I would like to define a cache in code with
@Cacheable(cacheNames = "example_cache"
and have it inherit the basic-spec without any changes to property files
However, currently CaffeineSpecResolver.getCaffeineSpec
will only apply the basic-spec to caches which have a non-blank value for coffee-boots.cache.spec.example_cache
Try reducing amount of custom code by using newly introduced method registerCustomCache
.
Links:
It's a bit confusing that if you browse https://github.com/stepio/coffee-boots the "Releases" section links to 3.0.0 as the most recent release, and even hitting "Tags" in that view doesn't show anything later. The Readme also suggests version 2.2.0.
I had to go digging to find out that I should be using 4.0.0 for SB3 support; it would be nicer to make this more discoverable for others. Hopefully not too onerous a request 😃
I like to configure the caches via properties like:
coffee-boots.cache.spec.myCache1=maximumSize=100000,expireAfterWrite=1m
coffee-boots.cache.spec.myCache1=maximumSize=200000,expireAfterWrite=1m
For all caches I e.g. want expireAfterWrite=1m
It would be nice to be able to specify a default spec like:
coffee-boots.cache.default-spec=expireAfterWrite=1m
and then only overwrite the settings needed like:
coffee-boots.cache.spec.myCache1=maximumSize=100000
coffee-boots.cache.spec.myCache1=maximumSize=200000
Vulnerabilities
DepShield reports that this application's usage of org.assertj:assertj-core:3.4.1 results in the following vulnerability(s):
Occurrences
org.assertj:assertj-core:3.4.1 is a transitive dependency introduced by the following direct dependency(s):
• org.springframework.boot:spring-boot-starter-test:1.5.21.RELEASE
└─ org.assertj:assertj-core:3.4.1
This is an automated GitHub Issue created by Sonatype DepShield. Details on managing GitHub Apps, including DepShield, are available for personal and organization accounts. Please submit questions or feedback about DepShield to the Sonatype DepShield Community.
Trying to switch to coffee-boots, previously I could get metrics on the caches via prometheus and micrometer, when I switch to configuring the caches with coffee-boots they drop off the metrics endpoints. Any thoughts on how to get them back? I am using the same caffeinespec for all the caches, just changing the configuration from spring.cache... to coffeeboots.cache...
Hi
CaffeineSpecSpringAutoConfiguration.cacheManager is annotated with @ConditionalOnMissingBean and by default it makes a type check to determine if there is already such a bean. I think in this case we should be checking the bean by name: cacheManager since we are trying to understand if there is a default cache manager defined.
Fortunately there is a way to configure that annotation by bean name using the name attribute.
So, could you please update that annotation as:
@ConditionalOnMissingBean(name="cacheManager")
Background about how I bumped into this:
I wanted to configure a LoadingCache via properties file but it is not supported by this project. So I extended it, and using my own custom CacheManager as the default cache manager. So they are clashing because CaffeineSpecSpringAutoConfiguration is alse trying to register a bean with the same name: cacheManager
You can see some details of how I am doing it here: ben-manes/caffeine#311 in case you also want to use a LoadingCache.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.