Avoiding repeated Data Base calls for the same parameters using Java 8 or Spring data JPA

Kiran Nair :

I am having a data base call which is in Oracle and i am using Spring data JPA for that.

I do have a function which utilizes this db call to retrieve the result every time in the loop.

Now my problem is most of the time the combination of parameter values are repeating. How to avoid this and is there a way to store temporarily for the given set of combination and the corresponding result set without any caching mechanism.

Any luck in Java 8 or spring data JPA itself?.

Jens Schauder :

You have various options.

  1. If you are using Hibernate you may use it's query cache: https://vladmihalcea.com/how-does-hibernate-query-cache-work/ I'm not sure if EclipseLink has a similar feature.

  2. You may use Springs caching facility. https://spring.io/guides/gs/caching/

  3. And of course you may role your own by assembling all the parameters in a single object with proper equals and hashCode implementation and store the result in a HashMap

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=366937&siteId=1