组织内存缓存键
我试图找到一种好方法来处理内存缓存键,以便以更文明的方式在缓存层中存储、检索和更新数据。
发现了这个模式,看起来很棒,但是如何将它变成 PHP 应用程序的功能部分呢?
身份映射模式:http://martinfowler.com/eaaCatalog/identityMap.html
谢谢!
更新:我被告知修改后的memcache(memcache-tag)显然确实做了很多这样的事情,但我无法在我的Windows开发盒上安装Linux软件......
Im trying to find a good way to handle memcache keys for storing, retrieving and updating data to/from the cache layer in a more civilized way.
Found this pattern, which looks great, but how do I turn it into a functional part of a PHP application?
The Identity Map pattern: http://martinfowler.com/eaaCatalog/identityMap.html
Thanks!
Update: I have been told about the modified memcache (memcache-tag) that apparently does do a lot of this, but I can't install linux software on my windows development box...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗯,memcache 使用的是身份映射模式。您检查缓存,然后访问数据库(或您正在使用的其他任何内容)。您可以通过存储对象而不仅仅是值来查找有关源的信息,但这样做会降低性能。
您实际上无法询问缓存它包含什么列表。要大规模无效,您必须保留所输入内容的列表并迭代它,或者您必须迭代可能符合关注模式的每个可能的键。您指出的资源 memcache-tag 可以简化此操作,但它似乎并未与 memcache 项目内联维护。
因此,您现在的选择是迭代删除,或完全刷新缓存的所有内容。因此,我建议设计考虑是您应该问的问题。为了得到对您有用的答案,我这样询问:您为什么要这样做?
Well, memcache use IS an identity map pattern. You check your cache, then you hit your database (or whatever else you're using). You can go about finding information about the source by storing objects instead of just values, but you'll take a performance hit for that.
You effectively cannot ask the cache what it contains as a list. To mass invalidate, you'll have to keep a list of what you put in and iterate it, or you'll have to iterate every possible key that could fit the pattern of concern. The resource you point out, memcache-tag can simplify this, but it doesn't appear to be maintained inline with the memcache project.
So your options now are iterative deletes, or totally flushing everything that is cached. Thus, I propose a design consideration is the question that you should be asking. In order to get a useful answer for you, I query thus: why do you want to do this?