简体   繁体   English

通过URL缓存是一种很好的做法吗?

[英]Is caching by URL's a good practice?

I'm bulding a fairly large and complex CMS in PHP, and my plan is to implement caching on some parts of it (with the possibility of toggeling the cache on/off for specific pages/sections). 我正在用PHP构建一个相当大而复杂的CMS,我的计划是在它的某些部分实现缓存(可以为特定的页面/部分打开/关闭缓存)。 After some research I came to the conclusion that using the URL would be the best practice for locating and retreiving the cahced file. 经过一些研究后,我得出结论,使用URL将是查找和检索cahced文件的最佳实践。 My intention is to implement a "whole page" solution to avoid obtrusive querycaching and cache the entire page, for all pages that should be cached. 我的目的是实现一个“整页”解决方案,以避免对应该缓存的所有页面进行突出的查​​询缓存并缓存整个页面。

The pseudocode would go like this (date-modified excluded): 伪代码将像这样(日期修改排除):

$filename = md5($the_full_url);

if (file_exists($filename)) get_cached_file($filename);

else write_cached_file($filename);

Could this approach be considered good practice? 这种方法可以被视为良好做法吗?

I think it depends on if there is user generated content on the page, for example if I view the page and you view the page do we get different pages or both the same page? 我认为这取决于页面上是否有用户生成的内容,例如,如果我查看页面并且您查看页面,我们是否会获得不同的页面或同一页面? Is there any form of "dynamic" content on the page. 页面上是否有任何形式的“动态”内容。

Full page caches are the most economical IF the page isn't going to change on a user/user basis. 如果页面不会在用户/用户的基础上改变,则整页缓存是最经济的。 If they are likley to change on a user by user basis you can cache by [url.sessionid] if not then caching by the full url is fine. 如果他们可以逐个用户更改,你可以通过[url.sessionid]缓存,如果没有,那么完整网址的缓存是好的。

Another alternative it to cache parts of the page which are likley to remain constant (For example blog entries) 另一种替代方法是缓存页面中可能保持不变的部分(例如博客条目)

Finally there is data caching where you just cache the dynamic data from the database locally. 最后是数据缓存,您只需在本地缓存数据库中的动态数据。

The whole system depends upon your requirements. 整个系统取决于您的要求。

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

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