Spring Data Rest - 缓存 [英] Spring Data Rest - Caching

查看:35
本文介绍了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)

想法/评论?

推荐答案

在存储库级别实现此功能的最简单方法是使用 Spring 的 @Cacheable,如 Spring Data 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.

另一种选择是利用 HTTP 缓存,例如使用 Apache HTTPD 设置或 Varnish.

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

这篇关于Spring Data Rest - 缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆