1

I wish to include Smart PHP Cache layer on top of main script on site. It works great, but Smart Cache also caches some pages which should not be cached (search results, admin area...).

I looked into Smart PHP Cache source code, and I am not sure if there is some way to configure which pages should be excluded from cache, or how to configure it.

So, what I need is some php code which will be inserted at top of main script of site, before Smart PHP Cache code which will first check if page contains for example:

"/search/"

"/admin/"

"/latest/"

"/other-live-pages/live-page.php"

and then, if something from above example is in URL to do nothing, (not to include smart_cache.php and to continue with other normal code, so user could see live results) and otherwise if there is nothing from above to include smart_cache.php.

Or.

If you have better knowledge to make modification inside Smart PHP Cache to be able to exclude some URLs from caching mechanism (or to tell me how to do that, because it looks like there is something in configuration of Smart PHP Cache that can bypass the cache layer but I am not sure how to use it.

Best regards.


Question update:

Thanks for answer. It works nice, I just wish to ask can you please little change code to make this:

If "pos1" (if URL contains "/search"), than nothing, false, like it is now

if "pos2" (if URL contains "/admin"), than nothing, false, like it is now

if "pos3" (if URL contains "/latest") include file "smart_cache_latest.php"

and after that like it is now, include "smart_cache.php" for any other URLs.

So practically only change is for URLs with "/latest", which should be cached too by including "smart_cache_latest.php".

Best regards.

1 Answer 1

2
$currenturl = $_SERVER['REQUEST_URI'];
$pos1 = strpos($currenturl, "/search");
$pos2 = strpos($currenturl, "/admin");
$pos3 = strpos($currenturl, "/latest");

if ($pos1 === false && $pos2 === false){
    require '/path/to/smart_cache.php';
} elseif($pos3 == true) {
    require '/path/to/smart_cache_latest.php';        
}
Sign up to request clarification or add additional context in comments.

7 Comments

Thanks, it works nice. I just changed '$currenturl = $_SERVER['PHP_SELF'];' to '$currenturl = $_SERVER['REQUEST_URI'];' because I have variables in URLs.
About "Supposed method" If I make to clear cache every 1 second then every page is cached for 1 second, even pages I wish to cache to longer time.
Yes that is correct. I didn't put any conditonal in that code snippet.
Do you have any thoughts or solution for "Question update"? Any help would be appreciated.
It does not require '/path/to/smart_cache.php' for pages with "/search", "/admin" and it does require '/path/to/smart_cache.php'; for other pages just like it should. But, it DOES NOT require '/path/to/smart_cache_latest.php' for pages with "/latest" at all.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.