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

1.5k Views Asked by At

I have a home page as index.php and it gives a list of 10 items/ products.

Now, I am using the same page as landing page for inward traffic from facebook. The url looks like index.php?productID=Q231 This page displays the product carrying the specified ID only.

I am aware of PHP output caching but I am new. I have learned that if I cache index.php, it will serve the same cached file to all the inward traffic from 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 a a 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.

3

There are 3 best solutions below

1
giorgio On

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. 'external' caching systems, like inbuild caching in smarty for example, output. I think you'd only need to 'disable' caching for browsers, which will mean, send the proper headers with header(...)

0
Paul Bain On

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 i.e. using productId in your case
  • 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/

1
srbhbarot On

You are using output caching. Then you should clear cache when your facebook or twitter links called. IN codeigniter(Framework of PHP), I have done this by clearing cache.

In core PHP, I don't know how to clear cache. 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?

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

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