duanqianwei2485
2011-04-13 23:45
浏览 23

PHP Memcache潜在的问题?

I'll most probably be using MemCache for caching some database results. As I haven't ever written and done caching I thought it would be a good idea to ask those of you who have already done it. The system I'm writing may have concurrency running scripts at some point of time. This is what I'm planning on doing:

  1. I'm writing a banner exchange system.
  2. The information about banners are stored in the database.
  3. There are different sites, with different traffic, loading a php script that would generate code for those banners. (so that the banners are displayed on the client's site)
  4. When a banner is being displayed for the first time - it get's cached with memcache.
  5. The banner has a cache life time for example 1 hour.
  6. Every hour the cache is renewed.

The potential problem I see in this task is at step 4 and 6. If we have for example 100 sites with big traffic it may happen that the script has a several instances running simultaneously. How could I guarantee that when the cache expires it'll get regenerated once and the data will be intact?

图片转代码服务由CSDN问答提供 功能建议

我很可能会使用MemCache来缓存一些数据库结果。 由于我没有写过和完成缓存,我认为向你们这些已经完成它的人提出这个问题是个好主意。 我正在编写的系统可能在某些时候运行脚本并发。 这就是我打算做的事情:

  1. 我正在写一个横幅交换系统。
  2. 有关横幅的信息存储在数据库中。
  3. 有不同的网站,流量不同,加载一个php脚本,为这些横幅生成代码。 (以便横幅显示在客户端的网站上)
  4. 第一次显示横幅时 - 它会被缓存缓存。
  5. 横幅有 缓存生存时间,例如1小时。
  6. 每隔一小时更新一次缓存。

    我在此任务中看到的潜在问题是步骤4和6. 如果我们有100个流量大的网站,则脚本可能会发生 几个实例同时运行。 我怎么能保证当缓存过期时它会重新生成一次并且数据将完好无损?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题