EclisepLink L2 cache When does its content in it get removed
We recently encountered a issue in our application in production environment. We updated our application version in production environment and ever since there were more queries going to DB. No change itself were made in Application concerning any additional queries. There are some days where these additional queries were not sent and some days where these additional queries were sent to DB. We enabled eclipselink jpa logging to find that the entitymanager.find on some days results in additional call to database where on some days the data seems to be returned from cache istead of Db call. I assume that this is the eclipselink L2 cache which holds this data and when cache miss occurs db query is fired. Am i correct in the above statement? If my above statement is correct, then what are the reasons why on some days the data what application is looking for is missing in cache? We have not done any additional code to clear any cache to our knowledge? Also where exactly whould this L2 cached data be present? Would it be in Heap memory? What effect would Garbage collection have on this L2 cache?
There are a number of Docs on the EclipseLink site that go into more detail on its caching and how it works. I'd suggest you check out https://www.eclipse.org/eclipselink/documentation/2.4/concepts/cache001.htm and https://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Basic_JPA_Development/Caching/Configuring first and then ask your specific questions, and there are many reasons why something might be in the cache on one day and not on the next depending on the settings. By default, the shared L2 cache uses as soft cache and weak identity map references, so objects no longer referenced by the application can be garbage collected.