我应该使用什么类型的缓存? [英] What type of caching should I use?

查看:90
本文介绍了我应该使用什么类型的缓存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个分类网站,它使用PHP和MYSQL。

我也有几个使用javascript的页面。



我需要知道使用什么类型的缓存来提高我的网站的性能...
有很多'常量'图像,如菜单,边栏,背景图像可能可以缓存在



你知道网页浏览器会自动缓存这些图片,还是必须编写一段代码来完成它?



我需要正确的方向指导...



另外,有没有办法以某种方式缓存大型PHP函数? (比如当你在Windows中打开一个应用程序时,应用程序会以某种方式被缓存,并且下次打开它时,如果你还没有启动你的计算机,它将快速打开。)



Thanks

解决方案

您可以使用mod_expire(如果您使用apache作为web服务器)在你的静态内容(JS,图像,图标,纯HTML)上,所以浏览器在它到期之前不会请求这个对象。根据您的托管和您的受众,使用服务作为akamai托管您的静态内容(图像,CSS,JavaScript)可能是一个好主意。

为了开始提高服务器端(PHP)的性能,您必须找出瓶颈。一个好的做法是在你的网站上实现一些日志记录(SQL查询和获得结果的秒数,最常查看哪个页面,哪个功能花费最多时间)。你会让它运行几周/几天。分析一下,你会知道什么SQL查询缓存,重构什么函数。

如果您急于快速和肮脏的方法是获得排名前10位的最受欢迎页面并将它们缓存在磁盘上。它可以工作,但如果你的网站真的是动态的并且几乎需要实时的信息,你就会经常使缓存无效。此外,如果您的网站有某些登录/注销过程,则可能会造成问题。另一种方法是缓存这些页面的一部分,通常生产成本更高(数据库/访问,处理复杂)。

就PHP而言,您可以使用PHP做这样的缓存处理:


I have a classifieds website, which uses PHP and MYSQL.

I have several pages which uses javascript also.

I need to know what type of caching to use to increase performance on my site... There is alot of 'constant' images like menues, sidebars, background-images which probably can be cached in a way.

Do you know if web-browsers cache these images automatically or if I have to write a piece of code to do it?

I need guidance in the right direction...

Also, is there a way to somehow cache large php functions? (like when you open an application in windows, the app gets cached somehow, and next time you open it it will open alot faster, if you haven't rstarted your computer that is.)

Thanks

解决方案

You can use mod_expire (if you are using apache as webserver) to set the expire HTTP header on your static content(js,images,favicon,plain HTML), so the browser won't request this object until it expires. Depending on your hosting and your audience it might be a good idea to use service as akamai to host your static content (images, css, javascript).

For starting to improve the performance of the server side (PHP), you have to identify bottlenecks. A good approach for doing that would be to implement some logging on your website (SQL queries and how many seconds to get results, what page are most viewed, what function take the most time). You will let this run few weeks/days. Analyze that and you would know what SQL queries to cache, what function to refactor.

If you are in hurry a quick and dirty approach is to get the top 10 most viewed page and cache them on disk. It would work but if your website is really dynamic and need information almost in real time you going to have invalidate that cache often. Also it can create problem if there is some login/logout process in your website. Another approach is to cache some part of those page, usually the more expensive to produce (DB/access, complicate processing).

In term of tools you can have on PHP to do such cache handling:

  • APC: that tool have some caching feature, plus PHP precompilation
  • memcached: a distibuted caching system
  • eAccelator: pre compilation
  • xcache: pre compilation

这篇关于我应该使用什么类型的缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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