I am using Hibernate through Spring JPA repository to build my Spring Boot apps. Since the apps will be running on docker in Kubernetes pod with limited resources, I want to have a good sense of how memory is being used by Hibernate for 1st level cache. As far as I understand, 1st level cache is only exist within a session which only spans over 1 request/response (default open-in-view session strategy of spring boot). However, within a request, there are quite a number for Spring JPA repositories being used to fetch data. As I did some tests, I found that when a findAll() is used, I saw one sql query being executed which means the cache was not used. However, when a findById() was used, only the 1st call resulted in a SQL query being executed which means the result was from the cache.
Here is my questions
1/is there a documentation about which query Hibernate will cache the result?
2/is there anyway to limit the cache size ?
3/if there is no reference to the query result, is the cache still valid? For example
BigEntity bigEntity1 = bigEntityRepo.findById(1);//load 1 record, cached it and make bigEntitys refer to the cached objecy
bigEntity1 = null; //now nothing refer to the cached object, it is still valid or being marked for GC
4/if i have to look at the source, which class should i look to understand the impl of 1st level cache