Is it relevant to use @Cacheable with in memory database ?
I am using h2 in memory database and just wondering that use of @Cacheable can improve the performance of application.
My application will have frequent get calls for the static data from database
Asked
Active
Viewed 124 times
0

Datta Diware
- 602
- 1
- 5
- 16
-
`@Cacheable` is not used to improve the performance of your DB. You improve the performance of your app, by caching frequent results from the DB. Have a look at this tutorial to get you started: https://www.baeldung.com/spring-cache-tutorial. – Alexandru Somai Feb 28 '20 at 14:51
-
1There are too many variables here. No one will be able to say without a _lot_ more information, by which point you could just try with and without and see if there's a performance benefit. But to _directly_ answer, caching _can_ improve the performance... Whether it will or not for your specific use case I don't think you're going to get an answer to. – BeUndead Feb 28 '20 at 14:59
-
My original question is that it at all relevant ? Because most important use of caching us to save frequent IO calls to the database hence when database itself is in memory, does caching actually relevant ? – Datta Diware Feb 28 '20 at 15:11
1 Answers
1
Generally - yes, it is.
In your case - I don't know, you didn't give enough info.
If you are doing a lot of small queries just to extract data (select by primary key etc.), then it's not worth it. Wouldn't be worth it even with regular database, unless you have terrible connection or something.
If you are doing huge queries, which take lot of time to find the data - then yes, definitely, same as with regular database.

Shadov
- 5,421
- 2
- 19
- 38