Memcache处理高延迟Web服务API-好主意吗? [英] Memcache to deal with high latency web services APIs - good idea?

查看:83
本文介绍了Memcache处理高延迟Web服务API-好主意吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个PHP应用程序,该应用程序在呈现包含那些对象的网页之前,会调用Web服务API来获取一些对象.在某些情况下,这些API确实很慢(秒),从用户体验的角度来看这是不可接受的.我知道我可以做的两件事...

I have a PHP application that calls web services APIs to get some objects before rendering a web page that incorporates those objects. In some cases these APIs are really slow (seconds) and that is not acceptable from a user experience point of view. Two things I know I can do...

  1. 使用ajax并在后台进行这些调用
  2. 使通话超时并在通话时间过长时优雅降级

都不是理想的,因此我正在考虑使用memcache(用于memcached的PHP扩展)来缓存从第三方Web服务获得的对象.这些对象将由加载同一页面的不同用户多次加载,因此这似乎很有意义.

Neither is ideal, so I was thinking about using memcache (the PHP extension for memcached) to cache the object that I get from the 3rd party web service. The objects will be loaded many times by different users loading the same page, so this seems to make sense.

对象相对较小(〜1k).

The objects are relatively small (~1k).

这听起来像是一种合理的方法吗?我知道memcached最初是为了减轻数据库负载而设计的,所以我想知道是否有我未曾看到的陷阱.

Does this sound like a reasonable approach? I know memcached was originally designed to alleviate database load, so I'm wondering whether there is a gotcha somewhere that I'm not seeing.

谢谢.

推荐答案

这是对内存缓存的完全合法使用.它不仅用于减少数据库负载,而且通常还用于缓存和对象存储. :)

This is a perfectly legitimate use of memcache. It is not only for database load reduction, it is for caching and object storage in general. :)

还要注意,PHP有两个用于memcached的接口.令人困惑的是,它们被命名为" memcache "和"内存缓存".阅读以下内容以在两者之间进行选择:

Also note, PHP has two interfaces for memcached. Confusingly, they are named "memcache" and "memcached". Read these to pick between the two:

  • https://serverfault.com/questions/63383/memcache-vs-memcached
  • http://code.google.com/p/memcached/wiki/PHPClientComparison

这篇关于Memcache处理高延迟Web服务API-好主意吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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