简体   繁体   English

如果网址中有查询字符串,是否跳过/绕过SERVER缓存文件/缓存?

[英]Skip/ bypass the SERVER cache file/caching if there's a query string in the url?

I have a home page as index.php and it gives a list of 10 items/ products. 我有一个主页作为index.php ,它提供了10个项目/产品的列表。

Now, I am using the same page as landing page for inward traffic from facebook. 现在,我使用与登陆页面相同的页面来接收来自Facebook的内向流量。 The url looks like index.php?productID=Q231 This page displays the product carrying the specified ID only. 网址看起来像index.php?productID=Q231此页面仅显示带有指定ID的产品。

I am aware of PHP output caching but I am new. 我知道PHP输出缓存,但是我是新手。 I have learned that if I cache index.php , it will serve the same cached file to all the inward traffic from facebook. 我了解到,如果我缓存index.php ,它将为来自Facebook的所有传入流量提供相同的缓存文件。

  1. Is my understanding correct? 我的理解正确吗? I have searched a lot about this but i am not clear as to how would one go about caching with this instance. 我已经对此进行了很多搜索,但是我不清楚如何使用该实例进行缓存。
  2. Is there aa way to skip or bypass the server cache file/caching if there's a query string in the url? 如果网址中有查询字符串,是否可以跳过或绕过服务器缓存文件/缓存?

I would greatly appreciate if anyone could give me some pointers. 如果有人可以给我一些指导,我将不胜感激。

It really depends on your caching model and how you handle this in your code. 它实际上取决于缓存模型以及如何在代码中处理它。

If you are creating the whole thing using output buffering you may want to use a method such as: 如果要使用输出缓冲创建整个内容,则可能需要使用以下方法:

  • Generate Cache key based on requested script and/or request parameters ie using productId in your case 根据请求的脚本和/或请求参数生成缓存密钥,即在您的情况下使用productId
  • Check to see if you have saved the output for a given key to some persistent store 检查是否已将给定密钥的输出保存到某个持久性存储中
    • If yes, output 如果是,输出
    • If no, then use an output buffer, generate the contents, save to a persistent store and save under the generated cache index, and output 如果否,则使用输出缓冲区,生成内容,保存到持久性存储并保存在生成​​的缓存索引下,然后输出

Googling brings up this rudimentary example: http://www.devshed.com/c/a/PHP/Output-Caching-with-PHP/ Googling提出了这个基本示例: http : //www.devshed.com/c/a/PHP/Output-Caching-with-PHP/

if i'm not mistaken caching is not based on referrer. 如果我没记错的话,缓存不是基于引荐来源网址。 Internal php caching is only to optimize code, it will not cache, as ie. 内部php缓存仅用于优化代码,因此不会缓存。 'external' caching systems, like inbuild caching in smarty for example, output. “外部”缓存系统,例如smarty中的内置缓存,例如输出。 I think you'd only need to 'disable' caching for browsers, which will mean, send the proper headers with header(...) 我认为您只需要为浏览器“禁用”缓存,这意味着发送带有header(...)的正确标题

You are using output caching. 您正在使用输出缓存。 Then you should clear cache when your facebook or twitter links called. 然后,当您的facebook或twitter链接被调用时,您应该清除缓存。 IN codeigniter(Framework of PHP), I have done this by clearing cache. 在codeigniter(PHP框架)中,我通过清除缓存来完成此操作。

In core PHP, I don't know how to clear cache. 在核心PHP中,我不知道如何清除缓存。 But there must be some methods to clear cache. 但是必须有一些清除缓存的方法。 So try for that. 因此尝试。

Here some links may be useful to you. 这里有些链接可能对您有用。

How to clear browser cache with php? 如何使用php清除浏览器缓存?

http://php.net/manual/en/function.clearstatcache.php http://php.net/manual/zh/function.clearstatcache.php

http://www.dreamincode.net/forums/topic/6519-clear-cache/ http://www.dreamincode.net/forums/topic/6519-clear-cache/

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

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