简体   繁体   English

缓存系统如何在php生命周期中有效?

[英]How is a cache system effective in the php lifecycle?

I'm a little confused here. 我在这里有点困惑。

I know that for every PHP request, the entire application is bootstrapped all over again. 我知道,对于每个PHP请求,整个应用程序都会重新引导。

Given this, how can a cache be effective, if all of the globals are reloaded for each and every request? 鉴于此,如果为每个请求重新加载所有全局变量,缓存如何才能生效?

For example: 例如:

User calls URI/user/view/123. 用户调用URI / user / view / 123。 User 123 is loaded from a database and stored in $user. 用户123从数据库加载并存储在$ user中。

Why would you cache the contents of $user - when you merely need to refer to the variable in order to get the contents? 为什么要缓存$ user的内容 - 当你只需要引用变量以获取内容时?

Am I missing the point? 我错过了这一点吗?

Thank you, 谢谢,

Its more like caching images, common database querys 它更像是缓存图像,常见的数据库查询

For instance say your site has a lot of articles and each article has categories. 例如,假设您的网站有很多文章,每篇文章都有类别。 And say you dont change categories very often, then using a cached result of a query of the categories table is preferable then doing the query. 并且说你不经常更改类别,然后使用类别表的查询的缓存结果然后进行查询。 this is a simplified example. 这是一个简化的例子。

Another example is with images, if your site needs like thumbnailed version of user photos that they have uploaded instead of having php use the GD library to rescale the image and etc just save a version of that thumbnail version and use it instead of running through the GD code again. 另一个例子是图像,如果你的网站需要像他们上传的用户照片的缩略图版本,而不是让php使用GD库来重新缩放图像等等,只需保存该缩略图版本并使用它而不是通过再次GD代码。

As always, an image is worth a thousand words, here it is :) 一如既往,一张图片胜过千言万语,这里是:)

在此输入图像描述

( source ) 来源

As you can see, you reload some PHP librairies (like the basic environment (Globals, Requests, Cookies, etc), but not everything (in this case, Security, Application, various libraries, Views). 正如您所看到的,您重新加载了一些PHP库(如基本环境(全局,请求,Cookie等),但不是所有内容(在本例中为安全性,应用程序,各种库,视图)。

You skip what can be cached ;) 你跳过可以缓存的东西;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM