How do I prevent cached pages from being served to logged in users/users with items in cart?

Discussion in 'LiteSpeed Cache General' started by taylormorgen, Mar 21, 2018.

  1. taylormorgen

    taylormorgen New Member

    I've successfully not cached pages when a user has an item in cart/is logged in/etc by setting a cookie such as page_contain_cache_token. I'd like to not SERVE those cached pages to other users. How do I prevent a user from being served cached pages while they're logged in or have an item in cart?
    Current rules:
    Code:
    <IfModule LiteSpeed>
    RewriteEngine On
    # cache should be available for HEAD or GET requests
    RewriteCond %{REQUEST_METHOD} ^HEAD|GET$
    # select which pages to cache
    RewriteCond %{HTTP_COOKIE} page_contain_cache_token=yes
    # excluding certain URLs
    RewriteCond %{REQUEST_URI} !/(login|checkout|cart|private|profile|cron|image)$
    # cache for 5 mins
    RewriteRule .* - [E=Cache-Control:max-age=300]
    </IfModule>
     
    Last edited by a moderator: Mar 22, 2018
  2. Pong

    Pong Well-Known Member Staff Member

    This is no general solution for all applications. Our plugin for different applications has kept such thing in mind and handles such things correctly.
    For non-plugin rewrite rules, you may need to figure out that CMS application logic. It may or may not have such easy exclusion rules for you for some applications.
     
  3. taylormorgen

    taylormorgen New Member

    I have application logic to set a cookie for users who shouldn't be served cached pages...what would the code in .htaccess be to prevent cached pages being served based on that cookie?
    Thanks,
    Doug
     
  4. Pong

    Pong Well-Known Member Staff Member

    If you have set login user with cookie "loginuser"
    You can try the following:
    Code:
    RewriteCond %{HTTP_COOKIE} !loginuser [NC]
    to replace your "
    Code:
    RewriteCond %{HTTP_COOKIE} page_contain_cache_token=yes
    By the way, which PHP application do you use?
     
    Last edited by a moderator: Mar 29, 2018
  5. taylormorgen

    taylormorgen New Member

    It's not the caching of the pages that's a problem...I have that set up already and the correct pages are getting cached. It's serving those cached pages to someone who shouldn't be served those pages.

    Unfortunately I'm stuck with Zen Cart for the time being. I'm pretty sure there isn't a prebuilt Litespeed cache plugin for it.
     
  6. Pong

    Pong Well-Known Member Staff Member

    We don't have any plan for ZenCart cash plugin at the moment.
    For rewrite rules, you will have to figure out how to exclude pages which should not be cached. Zencart may or may not support such condition in code. You may need to do some research to find out. seems a question to Zencart itself then and I would suggest you can ask from Zencart forum.
     

Share This Page