• Resolved fightsmarttrav

    (@fightsmarttrav)


    Hey guys, is there a way to ONLY cache a certain directory and exclude all other pages?

    All of the ‘paid’ pages on my site which have tons of dynamic content are under https://howtofightnow.com/course/pages and light speed cache works great for these, so I would love to cache ONLY the /course/ directory with light speed cache.

    I would prefer to use a different caching plugin for the other pages.

    Please let me know if this is possible, and thank you for your time!

Viewing 14 replies - 1 through 14 (of 14 total)
  • Plugin Support qtwrk

    (@qtwrk)

    add_action( 'template_redirect', 'check_product_category_and_set_variable' );
    
    
    function check_product_category_and_set_variable() {
    	
        if (strpos($_SERVER['REQUEST_URI'], "xxx") === false){
            do_action( 'litespeed_control_set_nocache', 'no-cache some page' );
        }
        else {
            do_action( 'litespeed_control_set_cacheable', 'cache for some page ');
        }
    }
    

    please replace the xxx to your targeted URI , partial match also works , add this code to your theme’s functions.php

    • This reply was modified 11 months ago by qtwrk.
    • This reply was modified 11 months ago by qtwrk.
    • This reply was modified 11 months ago by qtwrk.
    Thread Starter fightsmarttrav

    (@fightsmarttrav)

    this is amazing! Thank you for your reply. Ok, so in this case, do I need to include a wildcard, and if in the future I wanted to include multiple directories, would I separate with a comma?

    so for example, here I’m trying to cache only:

    https://howtofightnow.com/course/*

    so:

    add_action( ‘template_redirect’, ‘check_product_category_and_set_variable’ ); function check_product_category_and_set_variable() { if (strpos($_SERVER[‘REQUEST_URI’], “/course/*”) === false){ do_action( ‘litespeed_control_set_nocache’, ‘no-cache some page’ ); } else { do_action( ‘litespeed_control_set_cacheable’, ‘cache for some page ‘); } }

    If I wanted to add a directory, how would I do that? Comma separate like “/course/*,/videos/*”

    thank you again for your time and help!

    Plugin Support qtwrk

    (@qtwrk)

    no , it needs to be /course/ , but this is partial match and doesn’t matter the position , as /course/somethign/ and /something/course/ both match , to make it exact match as beginning of URI is bit of more complicated though

    if you have another target, then you can try

    
    add_action( 'template_redirect', 'custom_caching_rule' );
    
    
    function custom_caching_rule() {
    	
        if (strpos($_SERVER['REQUEST_URI'], "xxx") === false && strpos($_SERVER['REQUEST_URI'], "yyy") === false){
            do_action( 'litespeed_control_set_nocache', 'no-cache some page' );
        }
        else {
            do_action( 'litespeed_control_set_cacheable', 'cache for some page ');
        }
    }
    Thread Starter fightsmarttrav

    (@fightsmarttrav)

    Incredible! Thank you so much.

    Is there any way to confirm if this is working as expected?

    Plugin Support qtwrk

    (@qtwrk)

    you can check http response header on pages, if you see x-litespeed-cache-control: no-cache means this page is not cached

    otherwise you will see x-litespeed-cache: miss/hit , that means this page is cacheable

    Thread Starter fightsmarttrav

    (@fightsmarttrav)

    I must have done something wrong. I added:

    add_action( ‘template_redirect’, ‘custom_caching_rule’ );

    function custom_caching_rule() {

    if (strpos($_SERVER['REQUEST_URI'], "/course/") === false){
        do_action( 'litespeed_control_set_nocache', 'no-cache some page' );
    }
    else {
        do_action( 'litespeed_control_set_cacheable', 'cache for some page ');
    }

    }

    …but I’m getting this under cache on the following page:

    https://howtofightnow.com/course/the-head-movement-training-program/day-3/reading-your-opponent/

    (This definitely has /course/ in it)

    I’m getting: https://capture.dropbox.com/WgBCpEuvXT1Rs7se

    “Access-Control-Allow-Origin:

    Alt-Svc:

    h3=”:443″; ma=86400

    Cache-Control:

    no-cache, must-revalidate, max-age=0, no-store, private”

    …so I’m guessing that this did not work?

    THank you again for your time. Sorry I’m not great at this.

    Plugin Support qtwrk

    (@qtwrk)

    no , the cache-control is browser cache, nothing to do with our cache system

    but it seems you are not using LiteSpeed webserver, in this case, our plugin won’t be able to cache any pages at all.

    Thread Starter fightsmarttrav

    (@fightsmarttrav)

    Ok, currently I’m running apache on the front end, and nginx on the backend on a plesk server. Do you provide set up for Litespeed webserver as a service?

    I’m on an Ec2 instance as well.

    Just want to make this whole thing as fast as possible. Not sure if my wordpress application is compatible though.

    How could I find out?

    Plugin Support qtwrk

    (@qtwrk)

    in your case, without actual LSWS, you can check response header as well though

    for cacheable page , you should see x-litespeed-tag: xxxxx

    for no-cachebale page, you should see x-litespeed-cache-control: no-cache , or not seeing x-litespeed-tag at all

    installation on Plesk should be simple and easy , we have document and video guide if you want to do it yourself, and of course, we also have installation service as well if you want ??

    • This reply was modified 11 months ago by qtwrk.
    Thread Starter fightsmarttrav

    (@fightsmarttrav)

    Ok, I do see:

    X-Litespeed-Tag:

    d88_tag_priv,public:d88_HTTP.200

    Here’s a screenshot: https://capture.dropbox.com/vOPPt6aCiorw6KMp

    Does this mean that the page is being cached effectively?

    Thank you again for your time and help, and Merry Christmas!

    Plugin Support qtwrk

    (@qtwrk)

    yes that means this page is cacheable , but currently it is not actually cached as I have explained before due to webserver.

    Merry Christmas ??

    Thread Starter fightsmarttrav

    (@fightsmarttrav)

    Ok, do you guys provide paid set up services for litespeed web server?

    Plugin Support qtwrk

    (@qtwrk)

    yes of course, please check this page

    Thread Starter fightsmarttrav

    (@fightsmarttrav)

    Ok, so before I move forward with this, I’m just curious if litespeed web server is something that will typically run in conjuction with both apache and nginx. Right now, apache is responsible for most of the ‘front end’ stuff on my site, including php, but nginx runs some other functions. I believe that htis is due to the server being a plesk server.

    Will litespeed web server replace apache or nginx, or would it work in conjunction with them somehow?

    Also, this seems like it would be a major adjustment on my server. Is there any way to measure the actual benefit that I would receive on the page that I shared with you?

    If there is a way to show a performance increase, I would definitely move forward with the set up.

    Thank you!

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Only cache certain subdirectory’ is closed to new replies.