Multiple questions on caching #41839
Replies: 5 comments 8 replies
-
/cc @geoand (kotlin) |
Beta Was this translation helpful? Give feedback.
-
I did find an answer to my first question: https://quarkus.io/guides/hibernate-orm#caching This doesn't related to caching the results of functions for active record entities, nor refreshing caches. I'm assuming using the scheduling tools provided is the "correct" or "best" solution for now, unless someone says otherwise. |
Beta Was this translation helpful? Give feedback.
-
Perhaps @yrodiere can help with the question about Hibernate / JPA For the Cache with Caffeine question, @gwenneg can likely help |
Beta Was this translation helpful? Give feedback.
-
You don't. You only specify what needs to be cached, i.e. annotate entities or associations, or mark queries as cacheable. It's not your job to keep the cache up to date, it's Hibernate ORM's. The ORM will invalidate cache entries on write, try to get cache entries on read, and put cache entries on cache miss. There is of course some tuning involved (cache size, eviction, ...), but hopefully the docs should cover that. If something specific is not covered, please tell. Do note that the default caching solution (Caffeine) has limitations, though: https://quarkus.io/guides/hibernate-orm#limitations-of-caching I think @karesti has worked on integrating Infinispan as a caching solution, but I'm not sure she worked on integrating Hibernate ORM caching -- the docs certainly don't mention it. |
Beta Was this translation helpful? Give feedback.
-
Sorry for the late answer, I'm currently on PTO 😄 I don't think mixing Hibernate ORM caching and Setting the following property automatically leads to cached entries being removed from the cache 12 hours after they've been written. You don't need to perform any additional manual operation.
It doesn't look like you need |
Beta Was this translation helpful? Give feedback.
-
Hello! I'm trying to put together something with Quarkus + Kotlin + Hibernate Reactive + Panache.
The thing I'm running into now is working with caching. There's a few things.
Jakarta's caching
So we have some entity that's marked as cacheable with Jakarta:
Then that entity has a property that's marked with
@Cache
with HibernateMy question here is, is there any guidance from Quarkus as to how we should utilize this caching mechanism?
Caching with Caffeine
This is where things get a bit weirder. I'm going off of the information provided here.
Firstly is the issue of refreshing the cache. If we set the expiration after write to 12 hours in the application properties:
The question is: how do we refresh the cache? I understand one could do so with having
@CacheInvalidate
and@CacheResult
on some method that can be used forcibly refreshes the cache. I'm guessing the idea would be to schedule tasks to refresh the cache?So would the following be preferable?
But I assume that's not the correct way to use
@Scheduled
.The other thing is we're now mixing different kinds of caching, so there's a good chances things get a bit messy.
Beta Was this translation helpful? Give feedback.
All reactions