不同的文件缓存方法,缺点 [英] Different file caching methods, pros & cons

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

问题描述

我目前是为大学工作的刊登位置学生(网站开发人员),我已被指定几个大型网路专案。这些项目包括对大学的全面改革。帮助网站,每月大约14k点击从uni校园和大约4k外部。我还有一个第二个项目是移动版的第一个项目。

I am currently a placement student (web developer) working for a university, and I have been assigned a few big web projects. The projects include a total revamp of the university i.t. help site which draws around 14k hits a month from on the uni campus and around 4k externally. I also have a second project which is a mobile version of the first project. The projects will be sharing some resources.

要概括这个问题,以便答案对更多的人有用:

To generalise this question so the answers could be useful to more people:


  • 我有两个网站将共享一些资源,让我们说,index.php,functions.js和style.css,这些脚本将用于网站上的几乎所有页面。

  • 我有两个受众群体(在下载速度方面),网站托管的同一网络(100mb / s aprx)和外部用户中的用户。

我想知道什么是缓存每种脚本的最好方法(.js,.css,.php)如果可能,将利用其他方法的优点和缺点来完成。缓存我的意思是本地,网络和服务器缓存。

I would like to know what would be the best way to cache each kind of script (.js, .css, .php) and examples of how this would be done with their pros and cons over other methods if possible. By caching I mean locally, network and server caching.

注意:index.php是一个动态页面,应该每隔2小时从缓存刷新。如果你用.js,.css,.php或其组合来开始你的回答,那么很容易看到你正在谈论缓存的脚本类型。

Note: index.php is a dynamic page which should be refreshed from cache every 2 hours. It would be cool if you start your answer with .js, .css, .php or a combination so I can easily see what type of script you are talking about caching.

感谢所有!

推荐答案

通过cachine调整性能可以分为多层:

Performance tuning through cachine could be categorized into multi-layers:

  • Client-side (JS and CSS): Add an Expires or a Cache-Control Header will get it done for you. But note that there are more to do than only caching to enhance client-side performance. For detailes check Best Practices for Speeding Up Your Web Site
  • Server-side: this could be on many levels web server, scripting language, database, operating system, network, etc..

良好的介绍和操作系统,可以在许多级别上使用web服务器,脚本语言,数据库,操作系统,网络等。实用代码示例可在第9章(性能) - 开发大型Web应用程序中找到。它将讨论缓存CSS,Javascript,模块,页面,Ajax和过期头。

Good introduction and practical code examples can be found in Chapter 9 (Performance) - Developing Large Web Applications. It will talk about Caching CSS, Javascript, Modules, Pages, Ajax and Expire headers.

如果我们需要在服务器端保持简单,请执行以下操作: p>

If we need to keep things simple on server-side do the following:


  1. 安装 APC 扩展,这将使PHP通过所谓的操作码缓存更快。

  2. 使用这个简单的Pear库将整个页面缓存两个小时 PEAR :: Cache_Lite

  3. 对于每个数据库,SELECT查询缓存APC中的结果of 5 Min,md5散列SELECT语句,并将其用作APC缓存的键。 文档

  1. Install APC extension which will make PHP faster for you through the so called opcode caching. No special configuration, it will work silently for you.
  2. Cache the full page for two-hours using this simple Pear library PEAR::Cache_Lite.
  3. For each database SELECT query cache the result in APC with a TTL of 5 Min, md5 hash the SELECT statement and use it as key for APC cache. Docs

以后如果你有多个服务器,性能变得至关重要,那么你需要看看:

In future if you have multiple servers and the performance becomes to be crucial before then you will need to look at:


  1. 共享服务器之间的内存缓存。检查 Memecache 或甚至 Membase

  2. 您需要一个反向代理解决方案:这基本上是在您的用户和服务器服务器之间,以便它将服务HTTP请求,而不是您的服务器。您可以使用该清漆鱿鱼 Apache流量服务器

  3. Mysql innoDB引擎很慢,您可能需要使用更快的引擎,例如 XtraDB

  4. 然后也许你会发现理性数据库对你来说很慢。然后,您将使用键值解决方案,例如 MongoDB

  1. Shared memory caching between servers. Check Memecache or even Membase
  2. You need a reverse proxy solution: this basically layer between your user and server server so that it will serve the HTTP requests instead of your server. You can use for that Varnish, Squid or Apache Traffic Server.
  3. Mysql innoDB engine is slow, you may need to go for faster engine such as XtraDB
  4. Then maybe you will find that rational databases are stil slow for you. Then you will go for the key-value solution such as MongoDB.

最后,作为网络应用程序性能检查的参考:

Finally as references in web application performance check:


  1. 前端性能:高性能网站更快速的网站高性能JavaScript

  2. 后端性能: Pro PHP应用性能高性能MySQL

  1. Front-end Performance: High Performance Web Sites, Even Faster Web Sites and High Performance JavaScript.
  2. Back-end Performance: Pro PHP Application Performance and High Performance MySQL

这篇关于不同的文件缓存方法,缺点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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