Zend如何使用缓存组件 [英] Zend how to use cache component

查看:68
本文介绍了Zend如何使用缓存组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设您有这种情况:一个简单的博客主页,既可以加载静态内容,也可以加载动态内容. 静态内容由很少变化的图像组成.我还具有数据库驱动的动态内容.动态内容包含在您所有的博客文章(文本和图像)以及相关的用户评论中.动态内容从每小时开始定期更改为每天.

Let's say you have this scenario:a simple blog home-page that loads both static content as well as dynamic content. The static content is composed of images that rarely changes.I also have database-driven,dynamic content.The dynamic content consists in all of your blog posts (text and image) and related users comments.The dynamic content changes periodically from every hour to every day.

您将如何进行缓存?特别是假设用户发表评论或管理员正在向您添加/编辑帖子,您将希望手动触发缓存清除以获取此博客主页的更新版本?

How would you go with caching?And in particular supposing a user is leaving a comment or the admin is adding/editing a post to you would want to manually trigger the cache clearing to have the update version of this blog home-page?

感谢您的耐心等候.

路卡

再次感谢

推荐答案

因此,@ mingos显示了缓存的基本用法.他谈论通用缓存,这很好.但是,ZF几乎没有几种可用于不同事物的缓存机制.您不需要限制自己的一种类型的缓存.您可以将它们混合使用.例如,要缓存静态内容,请

So the basic usage of cache is shown by @mingos. He talks about generic cache, which is good. However, ZF has few different cache mechanisms that you can use for different things. You don't need to limit yourself for one type of cache. You can use a mixture of them. For example, for caching your static content Zend_Cache_Frontend_Page would be worth considering as it would generate a full html file of your static pages. If you have lots of config files, e.g. long routes.ini or whatever, you can cache them using Zend_Cache_Frontend_File. With this you would save time parsing the ini files for every request. Significant parts of your views could be cached using Zend_Cache_Frontend_Output, etc.

要缓存什么以及何时更新缓存是一个棘手的问题.这完全取决于您的内容更改的速度和频率.例如,如果您每秒喜欢100条新评论,那么每秒清洁100次评论缓存(即每个新评论)是没有意义的.最好将每个帖子的评论与其他帖子的评论分开缓存.然后,您将清理/刷新仅与此帖子关联的缓存.

What to cache and when to update a cache is a tricky question. It all depends on how fast and how often your content is changing. For example, if you have like 100 new comments per second, there is no point in cleaning your comment cache 100 times per second (i.e. for each new comment). It would be better maybe to have comments for each post cached separately from the comments of other posts. Then you would clean/refresh a cache associated with only this post.

这篇关于Zend如何使用缓存组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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