缓存GET调用REST式API的结果最好的方法 [英] Best way to cache RESTful API results of GET calls

查看:335
本文介绍了缓存GET调用REST式API的结果最好的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在前面,或作为GET请求我的RESTful API(Ruby编写)第一层来创建一个缓存层的最佳方式。

I'm thinking about the best way to create a cache layer in front or as first layer for GET requests to my RESTful API (written in Ruby).

不是每个请求可以被缓存,因为即使对于一些GET请求的API有验证请求用户/应用程序。这意味着我需要配置的请求缓存和每个缓存的答案是有效有多长。对于少数情况下,我需要例如在很短的到期时间15和下方。我应该能够让缓存条目由即使未到截止日期的API应用程序终止。

Not every request can be cached, because even for some GET requests the API has to validate the requesting user / application. That means I need to configure which request is cacheable and how long each cached answer is valid. For a few cases I need a very short expiration time of e.g. 15s and below. And I should be able to let cache entries expire by the API application even if the expiration date is not reached yet.

我已经想到了很多可能的解决方案,我的两个最好的想法:

I already thought about many possible solutions, my two best ideas:


  • 我自己(有在我的手的所有配置选项)的API(甚至在路由),高速缓存的逻辑第一层,存储到Memcached的答案和到期日期

  • first layer of the API (even before the routing), cache logic by myself (to have all configuration options in my hand), answers and expiration date stored to Memcached

Web服务器代理(高配置),也许像鱿鱼,但我从来没有使用代理像这样的情况之前,我完全不知道它

a webserver proxy (high configurable), perhaps something like Squid but I never used a proxy for a case like this before and I'm absolutely not sure about it

我也想过像一个光油缓存解决方案,我用清漆的正常的Web应用程序,它的IM pressive但配置是一种特殊的。但是,如果它是最快的解决方案,我会用它。

I also thought about a cache solution like Varnish, I used Varnish for "usual" web applications and it's impressive but the configuration is kind of special. But I would use it if it's the fastest solution.

这是其他的想法是缓存到Solr的指数,我已经使用在数据层不会查询大多数请求数据库。

An other thought was to cache to the Solr Index, which I'm already using in the data layer to not query the database for most requests.

如果某人有一个提示或良好来源阅读关于这个话题,让我知道。

If someone has a hint or good sources to read about this topic, let me know.

推荐答案

memcached是一个很好的选择,我看到你所提到的这个已经作为一个可能的选项。另外Redis的似乎是称赞有很多作为这个级别的另一种选择。

memcached is a great option, and I see you mentioned this already as a possible option. Also Redis seems to be praised a lot as another option at this level.

在应用级,在更细粒度的方法来高速缓存在按文件和/或模块基础的文件而言,本地存储始终是普通对象的用户可请求一遍一遍一种选择,甚至简单只是删除响应对象到会话,以便可以重复使用VS使另一个HTTP REST调用和适当的编码。

On an application level, in terms of a more granular approach to cache on a file by file and/or module basis, local storage is always an option for common objects a user may request over and over again, even as simple as just dropping response objects into session so that can be reused vs making another http rest call and coding appropriately.

现在的人来回走大约辩论VS清漆鱿鱼,双方似乎都各有利弊,所以我不能评论哪一个是好,但很多人说光油与调整Apache服务器是伟大的动态网站。

Now people go back and forth debating about varnish vs squid, and both seem to have their pros and cons, so I can't comment on which one is better but many people say Varnish with a tuned apache server is great for dynamic websites.

这篇关于缓存GET调用REST式API的结果最好的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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