0

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.

Andrew Barber
  • 39,603
  • 20
  • 94
  • 123
Roma
  • 1
  • 1
  • you does not want cache page of index.php when it comes from facebook. Am i right? – srbhbarot Jan 20 '12 at 10:53
  • yes, srbhbarot i don't want to serve the cached page.....and also not cache it if it comes from facebook or twitter..... – Roma Jan 21 '12 at 07:27

3 Answers3

1

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/

Paul Bain
  • 4,364
  • 1
  • 16
  • 30
0

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(...)

giorgio
  • 10,111
  • 2
  • 28
  • 41
  • hi giorgio...i am confused....why would i want to disable client/browser caching....i need it. I just don't want to serve the php cached file on the server to incoming traffic from facebook and twitter....as expalined in my question. – Roma Jan 21 '12 at 07:38
0

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/

Community
  • 1
  • 1
srbhbarot
  • 1,317
  • 12
  • 16