spring-cache

after upgrade to Spring Boot 2, how to expose cache metrics to prometheus?

…衆ロ難τιáo~ 提交于 2019-12-05 11:31:08
I recently upgraded a spring boot application from 1.5 to 2.0.1. I also migrated the prometheus integration to the new actuator approach using micrometer. Most things work now - including some custom counters and gauges. I noted the new prometheus endpoint /actuator/prometheus does no longer publish the spring cache metrics (size and hit ratio). The only thing I could find was this issue and its related commit . Still I can't get cache metrics on the prometheus export. I tried settings some properties: management.metrics.cache.instrument-cache=true spring.cache.cache-names=cache1Name

How to have spring cache store the ResponseBody and not the intermediary object

我怕爱的太早我们不能终老 提交于 2019-12-05 02:22:37
I use spring cache with this method which returns the queried value as JSON: @RequestMapping("/getById") @ResponseBody @Cacheable public HugeValue getHugeValueFromSlowFoo( @RequestParam(value = "id", defaultValue = "") String id ) { return Foo.getById( id ); } This works fine and the HugeValue-object is stored in the cache (Hazelcast in this case). I want to further improve this because the time taken to create JSON from the HugeValue is quite high. Can I tell spring cache to cache the JSON-ified version of my object ? I use Jackson with Spring Boot 1.2 and Spring 4.1 Ben Steinert Without

Asynchronous Cache Update With Spring Cache Abstraction

 ̄綄美尐妖づ 提交于 2019-12-04 23:20:19
问题 Using Spring's caching abstraction, how can I have a cache refresh an entry asynchronously while still returning the old entry? I am trying to use Spring's caching abstraction to create a caching system where after a relatively short "soft" timeout, cache entries are made eligible for refresh. Then, when they are queried, the cached value is returned, and an asynchronous update operation is started to refresh the entry. I would also Guava's cache builder allows me to specify that entries in

Spring @Cacheable default ttl

三世轮回 提交于 2019-12-04 15:47:41
I generally use the @Cacheable with a cache config in my spring-boot app and set specific TTL (time to live) for each cache. I recently inherited a spring boot app that uses @Cacheable without explicitly stating a cache manager and ttl. I will be changing it to be explicit. But I am not able to find out what are the defaults when there is nothing explicit. I did look at the docs but found nothing there Anthony Anyanwu With spring boot, I was able to achieve success with this: First, you need to add spring-boot-starter-data-redis artifact to your POM file. <dependency> <groupId>org

Using multiple cache implementations with Spring Cache

扶醉桌前 提交于 2019-12-04 12:43:42
问题 I'm working on a Spring Boot app where I need to use both distributed (e.g. Hazelcast ) and local (e.g. Guava ) caches. Is there a way to configure Spring Cache to use both when using @Cacheable and decide which implementation is needed based on the cache name? I tried with creating a configuration for both HZ and Guava defining the cache names inside, but Spring complains that it couldn't find the cache name that is supposed to handled by HZ. When I use exclusively HZ or Guava they work. 回答1

What are the best Cache practices in ehcache or spring cache for spring MVC?

隐身守侯 提交于 2019-12-04 01:13:02
Planning to implement cache mechanism for static data in spring web based application, can any one explain which is the best and how it works? EhCache Spring Cache Disclaimer : I am a Terracotta / Software AG employee, the maintainers of Ehcache Ehcache is a JVM caching library, famous for being used as the default 2nd level cache for the Hibernate ORM Spring cache was introduced in Spring 3.1, and brought annotations such as @CachePut to define uses of caches in a Spring application; by default Spring cache uses a plain Map, but you can configure it to use any popular caching framework,

Spring Caching not working for findAll method

妖精的绣舞 提交于 2019-12-03 16:53:34
I have recently started working on caching the result from a method. I am using @Cacheable and @CachePut to implement the desired the functionality. But somehow, the save operation is not updating the cache for findAll method. Below is the code snippet for the same: @RestController @RequestMapping(path = "/test/v1") @CacheConfig(cacheNames = "persons") public class CacheDemoController { @Autowired private PersonRepository personRepository; @Cacheable @RequestMapping(method = RequestMethod.GET, path="/persons/{id}") public Person getPerson(@PathVariable(name = "id") long id) { return this

ACL security in Spring Boot

社会主义新天地 提交于 2019-12-03 13:51:22
问题 I am having issues setting up ACL through Java config in a Spring Boot application. I have created one small project to reproduce the issues. I have tried a few different approaches. First issue I had was with EhCache, and after I fixed that (I assume I did) I couldn't login any more, and it looks like all the data is gone. There are 4 classes with different configurations: ACLConfig1.class ACLConfig2.class ACLConfig3.class ACLConfig4.class All @PreAuthorize and @PostAuthorize annotations are

Asynchronous Cache Update With Spring Cache Abstraction

£可爱£侵袭症+ 提交于 2019-12-03 13:51:17
Using Spring's caching abstraction, how can I have a cache refresh an entry asynchronously while still returning the old entry? I am trying to use Spring's caching abstraction to create a caching system where after a relatively short "soft" timeout, cache entries are made eligible for refresh. Then, when they are queried, the cached value is returned, and an asynchronous update operation is started to refresh the entry. I would also Guava's cache builder allows me to specify that entries in the cache should be refreshed after a certain amount of time. The reload() method of the cache loader

How update/remove an item already cached within a collection of items

泄露秘密 提交于 2019-12-03 12:36:39
I am working with Spring and EhCache I have the following method @Override @Cacheable(value="products", key="#root.target.PRODUCTS") public Set<Product> findAll() { return new LinkedHashSet<>(this.productRepository.findAll()); } I have other methods working with @Cacheable and @CachePut and @CacheEvict. Now, imagine the database returns 100 products and they are cached through key="#root.target.PRODUCTS" , then other method would insert - update - deleted an item into the database. Therefore the products cached through the key="#root.target.PRODUCTS" are not the same anymore such as the