Hi,
I'd like to have a /cache
actuator endpoint that will list all the cache regions will all the statistics for each cache region. More specifically:
GET /cache
[{
"id" : "simpleCMSWidgetData",
"stats" : {
"AverageGetTime" : 0.0,
"CacheHitPercentage" : 77.27273,
"CacheEvictions" : 0,
"AverageRemoveTime" : 0.0,
"CacheMisses" : 30,
"AveragePutTime" : 35.89833,
"CacheMissPercentage" : 22.727274,
"CacheHits" : 102,
"CacheRemovals" : 0,
"CachePuts" : 30,
"CacheGets" : 132
}
}, {
"id" : "productData",
"stats" : {
"AverageGetTime" : 0.0,
"CacheHitPercentage" : 50.0,
"CacheEvictions" : 0,
"AverageRemoveTime" : 0.0,
"CacheMisses" : 1,
"AveragePutTime" : 33.119,
"CacheMissPercentage" : 50.0,
"CacheHits" : 1,
"CacheRemovals" : 0,
"CachePuts" : 1,
"CacheGets" : 2
}
} ]
and
GET /cache/productData
{
"id" : "productData",
"stats" : {
"AverageGetTime" : 0.0,
"CacheHitPercentage" : 50.0,
"CacheEvictions" : 0,
"AverageRemoveTime" : 0.0,
"CacheMisses" : 1,
"AveragePutTime" : 33.119,
"CacheMissPercentage" : 50.0,
"CacheHits" : 1,
"CacheRemovals" : 0,
"CachePuts" : 1,
"CacheGets" : 2
}
}
and
DELETE /cache
would clear all the cache
and
DELETE /cache/productData
would clear the given cache region.
Comment From: snicoll
Not all cache library exposes that level of information I guess.
I also think @olivergierke has some concerns regarding DELETE
on a Collection.
Comment From: philwebb
@paranoiabla What cache library do you currently use?
Comment From: ptahchiev
@philwebb I use jcache abstraction, but underneath is hazelcast.
Comment From: snicoll
So we have added the cache metrics in the actuator as part of #2633 - As far as the management endpoint to actually clear caches, I am not sure how we would do that.
Comment From: maximede
Hello, I just created a WIP branch for the clear cache endpoint. ( see https://github.com/maximede/spring-boot/commit/77ebbd17fcd2bac5e589f6acba8fd5228861b5c7 ) It still needs a bit of work ( like showing all the cleared cache in the response, adding a few test) but I wanted to see if this was something that could be useful (it would be for me) , and if it's the correct way to do it.
I'm basically calling cache.clear()
on all available caches. It should work with any cache who implement org.springframework.cache.Cache#clear
There is also an MvcEndpoint that currently respond on POST
/clear_cache (should be DELETE
)
A nice improvement would be to be able to choose which cache(s) we want to clear.
Let me know what you think
Comment From: maximede
Any insight about my commit ?
Comment From: snicoll
Duplicate of #12216
Comment From: cdalexndr
Missing documentation for this feature: https://docs.spring.io/spring-boot/docs/2.4.3/reference/html/production-ready-features.html#production-ready-endpoints Is it still present in recent versions?
Comment From: snicoll
I don't understand any of that. The link you provided has an entry for the cache endpoint. This section links to additional details for each endpoint including the caches endpoint: https://docs.spring.io/spring-boot/docs/2.4.3/actuator-api/htmlsingle/#caches
Comment From: cdalexndr
@snicoll I opened docs from Spring Boot Reference Documentation where is only one entry for Spring Boot Actuator so I thought it contains the whole docs for actuator.
Didn't bother to read through whole docs, so I searched cache
keyword and didn't found any info about this feature.
It seems that there are more stacked doc pages, thanks.