PHP memcache设计模式 [英] PHP memcache design patterns

查看:91
本文介绍了PHP memcache设计模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



由于实现方式,无效是一个噩梦。我们从Memcache中学到了一些技巧,通过阅读邮件列表,例如允许一组密钥分组无效的技巧。对于那些知道它的人,请跳过下一段。



对于那些不了解有兴趣的人,诀窍是在你的密钥和存储中添加一个序列号memcache中的序列号。然后每次在你做你之前,你抓住当前的序列号,并建立你的钥匙。然后,为了使整个组无效,你只需增加序列号。



所以无论如何,我目前正在修改我们的模型来实现这个。



我的问题是..



我们不知道这种模式,我相信还有其他我们不知道的关于。我搜索过并且无法在网络上找到任何实现memcache,最佳做法等设计模式。



有人可以指出我这样的东西甚至只是写一个例子?我想确保我们不会让我们的新的重构中的初学者错误。

解决方案

缓存就是这样 - 对象/复杂结构的缓存。许多人犯了一个错误,把他们的缓存进行直接,高效的查询,这导致缓存检查/丢失的开销,当数据库获得的结果要快得多的时候。


$ b $这个建议是我被教给我的一个忠告;知道何时不缓存,也就是说,当开销消除感知的好处时。我知道这里没有回答具体的问题,但我认为这是值得指出的一个总体提示。


We use memcache basically as an after thought to just cache query results.

Invalidation is a nightmare due to the way it was implemented. We since learned some techniques with memcache thru reading the mailing list, for example the trick to allow group invalidation of a bunch of keys. For those who know it, skip the next paragraph..

For those who don't know and are interested, the trick is adding a sequence number to your keys and storing that sequence number in memcache. Then every time before you do your "get" you grab the current sequence number and build your keys around that. Then, to invalidate the whole group you just increment that sequence number.

So anyway, I'm currently revising our model to implement this.

My question is..

We didn't know about this pattern, and I'm sure there are others we don't know about. I've searched and haven't been able to find any design patterns on the web for implementing memcache, best practices, etc.

Can someone point me to something like this or even just write up an example? I would like to make sure we don't make a beginners mistake in our new refactoring.

解决方案

One point to remember with object caching is that it's just that - a cache of objects/complex structures. A lot of people make the mistake of hitting their caches for straightforward, efficient queries, which incurs the overhead of a cache check/miss, when the database would have obtained the result far faster.

This piece of advice is one I've taken to heart since it was taught to me; know when not to cache, that is, when the overhead cancels out the perceived benefits. I know it doesn't answer the specific question here, but I thought it was worth pointing out as a general hint.

这篇关于PHP memcache设计模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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