Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Data Rest - Caching

How to enable caching with Spring Data Rest?

The reasoning behind is that repository listing and search methods won't change once the application is up. Also if the data behind the rest API is changed only through rest API it does makes a case to enable caching data too.

I believe some level is caching happens in REST API framework and it would be ideal if the caching happens at the final response stage i.e., json response (to avoid the overhead of marshalling objects to json)

Thoughts/comments?

like image 392
Stackee007 Avatar asked Aug 21 '13 15:08

Stackee007


People also ask

Does spring data cache?

And since caching is not part of Spring Data JDBC and Spring Data JDBC repositories are just Spring Beans, you can combine it with any caching solution you like. The obvious choice is of course, Springs Caching abstraction behind which you can put any caching solution.

How do you cache data in spring boot?

If we want to enable a cache mechanism in a Spring Boot application, we need to add cache dependency in the pom. xml file. It enables caching and configures a CacheManager.

How do you caching in spring?

If we want to enable cache mechanism in a Spring Boot application, we need to add cache dependency in the pom. xml file. It enables caching and configures a CacheManager.


1 Answers

The easiest way to implement this on the repository level is to use Spring's @Cacheable as it can be seen in the Spring Data JPA Examples project.

Another option is to leverage HTTP Caching using the Apache HTTPD settings or a Varnish for example.

like image 159
Oliver Drotbohm Avatar answered Oct 03 '22 18:10

Oliver Drotbohm