Spring Data Rest-缓存

Spring Data Rest-缓存

问题描述:

如何使用Spring Data Rest启用缓存?

How to enable caching with Spring Data Rest?

背后的原因是,一旦应用程序启动,存储库列表和搜索方法就不会改变。另外,如果仅通过rest API更改了rest API背后的数据,它的确也有理由启用缓存数据。

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.

我相信REST API中存在某种程度的缓存框架,如果缓存发生在最终响应阶段,即json响应(以避免将对象编组到json的开销),那将是理想的选择

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)

想法/评论? / p>

Thoughts/comments?

在存储库级别实现此目的的最简单方法是使用Spring的 @Cacheable ,如在 Spring数据中所见JPA示例项目

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.

另一种选择是使用Apache HTTPD设置或Varnish来利用HTTP缓存。

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