Caching but Cache Expire Time / purging does not work.

Discussion in 'LiteSpeed Cache' started by astewart, Oct 23, 2013.

  1. astewart

    astewart New Member

    Hey guys,
    I'm looking to go with the 2-CPU license for LSWS, I'm on the 15 day trial now but I can't seem to get the Caching to work properly. Well, actually the purging / Cache Expire Time.

    First off I have a cPanel Server running Centos 6.4 without about 15 sites hosted off it.
    Software versions:
    PHP 5.4.17
    LSWS 4.2.4

    LSWS Cache Setting: (Globally disabled)
    Code:
    Enable Cache No
    Cache Expire Time (seconds) Not Set
    Cache Request with Query String Yes
    Cache Request with Cookie Yes
    Cache Response with Cookie Yes
    Ignore Request Cache-Control Yes
    Ignore Response Cache-Control Yes
    Enable Private Cache No
    So I plan on enabling cache by means of the .htaccess file only.
    HTACCESS file contents:
    Code:
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    CacheEnable
    RewriteCond %{ORG_REQ_URI} !^/wp-admin/
    RewriteCond %{ORG_REQ_URI} !^/wp-admin$
    RewriteRule ^index\.php$ - [L,E=Cache-Control:max-age=120]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    I have successfully gotten cache enabled for one of my Wordpress sites but the Cache Expire Time / purging doesn't seem to happen in the amount of seconds I set it to, which is 120 seconds.

    Here is what I get from doing the Curl test:

    Code:
    user@host [/]# curl -I http://www.stewartfamilypei.com/ HTTP/1.1 200 OK
    Date: Wed, 23 Oct 2013 13:38:37 GMT
    Server: LiteSpeed
    Connection: Keep-Alive
    Keep-Alive: timeout=5, max=100
    Transfer-Encoding: chunked
    [B]X-LiteSpeed-Cache: hit[/B]
    X-Pingback: http://www.stewartfamilypei.com/xmlrpc.php
    Expires: Wed, 11 Jan 1984 05:00:00 GMT
    Cache-Control: [B]no-cache[/B], must-revalidate, max-age=0 (no-cache??)
    Pragma: no-cache
    Content-Type: text/html; charset=UTF-8
    So it looks like it is caching fine but I'm not sure why the cache-control has no-cache. Besides that I have done the "test.php" test which has the time and date, to keep refreshing to watch it update in the proper amount of time but that cache page never seems to update.

    Is it not taking into account the 120 seconds for this?

    Any help would be great, as I would like to get this working properly.

    Thanks guys!

    Regards,
  2. NiteWave

    NiteWave Administrator

    in .htaccess, replace

    CacheEnable

    with

    Rewrite . - [E=Cache-Control:max-age=60]

    see if any issue.
  3. astewart

    astewart New Member

    Hi Nitewave,
    Unfortunately that didn't change a thing, it actually stops caching when I add that. This is what I have:
    Code:
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    Rewrite . - [E=Cache-Control:max-age=60]
    RewriteCond %{ORG_REQ_URI} !^/wp-admin/
    RewriteCond %{ORG_REQ_URI} !^/wp-admin$
    RewriteRule ^index\.php$ - [L,E=Cache-Control:max-age=120]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    It looks like the rewrite line you gave me is incorrect, as all it says is "Rewrite". Shouldn't that be "RewriteRule"?

    Is there anything else I can try. I would love to stick with Litespeed but I may have to look at other avenues if I can't get the caching working right.

    -- Adam S
  4. NiteWave

    NiteWave Administrator

    you're right. Sorry, should be "RewriteRule". have you tried it ?
  5. astewart

    astewart New Member

    Yes, I have tried it.
    It doesn't cache at all when I have that in there.
  6. NiteWave

    NiteWave Administrator

    please change the rule to

    RewriteRule (.*) - [E=Cache-Control:max-age=60]

    what's your setting for Server->Cache
    Storage Path
    Max Object Size
  7. astewart

    astewart New Member

    I gave that a try and it didn't work either. Here is my current .htaccess file:
    Code:
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule (.*) - [E=Cache-Control:max-age=60]
    RewriteCond %{ORG_REQ_URI} !^/wp-admin/
    RewriteCond %{ORG_REQ_URI} !^/wp-admin$
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    Here is what I have for storage and max object size:
    Storage Path: /dev/shm/diskcache
    Max Object Size: 118600

    As mentioned in my first post with the .htaccess I originally posted, I was able to get items to cache but they were not refreshing.

    For now I have implemented a temporary work around so that ALL cache is removed every 5 minutes:
    Code:
    */5 * * * * find /dev/shm/diskcache -type f -mmin +5 -delete 2>/dev/null
    I would rather the cache expires per site though and not set at a global level.
  8. NiteWave

    NiteWave Administrator

    I re-read your first post:
    it's because in global setting:
    Cache Expire Time (seconds) Not Set

    if you set to 120 seconds, then it'll work as expected.

    this header is generated by php. since global setting
    Ignore Response Cache-Control Yes
    so it's ignored by lsws, just pass it as it is.
    only this header
    X-LiteSpeed-Cache: hit
    is generated by litespeed, and indicate it's a cached page.

    to be accurate, all cache generated 5 minutes ago are removed.
  9. astewart

    astewart New Member

    You are correct when you say the cron runs every five minutes and removes all cached objects that are older then 5 minutes :)

    What I;m trying to find out here is if I have "Ignore Response Cache-Control Yes", then isn't there a way to set the expire time in the .htaccess file?

    As an example, shouldn't "RewriteRule (.*) - [E=Cache-Control:max-age=60]" set the the cache expire time to 60 seconds. Once the 60 seconds is up it creates a new cached file?

    Do you see what I mean?
  10. NiteWave

    NiteWave Administrator

    of course it will. but won't be automatically, only when receive an new request, it'll check if the cache is there and not expire. if not expire, will return the cache. if cache not exist or already expire, it'll pass the request to backend php process and get the response from it. then replace the old cache with the new response.
  11. astewart

    astewart New Member

    And this is my problem. It is not replacing the expired cache.

    I have tried with each of the following one at a time and still the cache doesn't expire in 60:
    Code:
    RewriteRule ^index\.php$ - [L,E=Cache-Control:max-age=60]
    
    RewriteRule . - [E=Cache-Control:max-age=60]
    
    RewriteRule ^index\.php$ - [L,E=Cache-Control:max-age=60]
    
    RewriteRule (.*) - [E=Cache-Control:max-age=60]
    
    RewriteRule /(.*\.php)?$ – [L,E=Cache-Control:max-age=60]
    
    RewriteRule /(.*\.php)?$ – [E=Cache-Control:max-age=60,L]
    
    None of the above worked. The cache never expires and is never refreshed
    Last edited: Oct 25, 2013
  12. NiteWave

    NiteWave Administrator

    please create a test case so that other can reproduce it

    you can create a test.php which only show timestamp.

    the rewriterule can be
    RewriteRule ^test.php$ - [E=Cache-Control:max-age=60]

    use
    #curl -i domain/test.php

    to check the result. test in after 30 seconds, 60 seconds, 100 seconds etc.
    post the result here.

Share This Page