[Resolved] max-age in response ignored?

Status
Not open for further replies.

anything

Well-Known Member
#1
i thought I'd try looking into using the lsws cache to replace my varnish layer, but i just dont get it.

i have php content already sending dynamic expires and cache-control headers, but they seem to be completely ignored in my tests. instead i have to staticly configure a huge list of rewrite rules with hardcoded cache times for each url? seems like a huge waste of effort.

varnish requires one extra line of config that says 'just use whatever the max-age in the response as a ttl'.
 

anything

Well-Known Member
#3
sorry i should have included what ive already tried.

i can get content to be cached, but max-age is still ignored.

lsws enterprise 2 cpu 4.2.23
Code:
Enable Cache No
Max Object Size    128K
Cache Expire Time (seconds) 60
Cache Stale Age (seconds) 5
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 No
Enable Private Cache No
Private Cache Expire Time (seconds) 0
/test/.htaccess
Code:
<IfModule LiteSpeed>
CacheEnable public /
</IfModule>
/test/test2.php:
PHP:
<?
header("Cache-Control: public, max-age=20");
header('Expires: '.gmdate('D, d M Y H:i:s',time()+20).' GMT');
print "test=".time();
?>

Code:
$ wget -O - -S http://localhost/test/test2.php 2>&1| grep -E 'Cache|test'
--2015-05-16 03:19:56--  http://localhost/test/test2.php
  Cache-Control: public, max-age=20
test=1431710396
$ wget -O - -S http://localhost/test/test2.php 2>&1| grep -E 'Cache|test'
--2015-05-16 03:19:58--  http://localhost/test/test2.php
  X-LiteSpeed-Cache: hit
  Cache-Control: public, max-age=20
test=1431710396
$ wget -O - -S http://localhost/test/test2.php 2>&1| grep -E 'Cache|test'
--2015-05-16 03:20:19--  http://localhost/test/test2.php
  X-LiteSpeed-Cache: hit
  Cache-Control: public, max-age=20
test=1431710396
$ wget -O - -S http://localhost/test/test2.php 2>&1| grep -E 'Cache|test'
--2015-05-16 03:20:25--  http://localhost/test/test2.php
  X-LiteSpeed-Cache: hit
  Cache-Control: public, max-age=20
test=1431710396
$ wget -O - -S http://localhost/test/test2.php 2>&1| grep -E 'Cache|test'
--2015-05-16 03:20:32--  http://localhost/test/test2.php
  X-LiteSpeed-Cache: hit
  Cache-Control: public, max-age=20
test=1431710396
$ wget -O - -S http://localhost/test/test2.php 2>&1| grep -E 'Cache|test'
--2015-05-16 03:20:56--  http://localhost/test/test2.php
  X-LiteSpeed-Cache: hit
  Cache-Control: public, max-age=20
test=1431710396
$ wget -O - -S http://localhost/test/test2.php 2>&1| grep -E 'Cache|test'
--2015-05-16 03:20:59--  http://localhost/test/test2.php
  Cache-Control: public, max-age=20
test=1431710459
$ wget -O - -S http://localhost/test/test2.php 2>&1| grep -E 'Cache|test'
--2015-05-16 03:21:03--  http://localhost/test/test2.php
  X-LiteSpeed-Cache: hit
  Cache-Control: public, max-age=20
test=1431710459
as you can see, it was cached for 60 seconds, not 20.

i tried setting Cache Expire Time (seconds)=not set, but its cached for a long time (86400 probably)
and Cache Expire Time (seconds)=0 means nothing is cached at all.



also seems that cannot strip headers (eg, set-cookie) for cacheable content, only exclude such content?

nor can i choose to cache 404's, 301's and 302's (wordpress 404's are very expensive, dos danger here!)
(i found that a rewrite rule can force caching of a 404 if i know the url beforehand, but couldnt think of any other way)

id really like to dump the extra varnish layer. but it seems like litespeed cache isn't flexible enough for me.
perhaps these are some features you might add later.
 
Last edited by a moderator:

NiteWave

Administrator
#5
/test/test2.php:
<?
header("Cache-Control: public, max-age=20");
header('Expires: '.gmdate('D, d M Y H:i:s',time()+20).' GMT');
print "test=".time();
?>
the response header "Cache-Control" is ignored by ls cache. (for current version)
this is different with how varnish works.

the "Cache-Control" header from backend server will pass to end user but not used by ls cache.

how long will ls cache a page is determined in lsws configuration, for example .htaccess
Code:
RewriteRule /test/test2,php - [E=Cache-Control:max-age=300]
will cache test2.php for 300 seconds.

the 300 is used by ls cache internally, not expose to end user in response header.
 
Last edited by a moderator:

anything

Well-Known Member
#6
ok thanks.
seems varnish is still the way to go for us for now.

i would suggest including it as a feature some time in the future.
all browsers and other reverse proxies already do the same.
 

mistwang

LiteSpeed Staff
#7
I believe that in your test case, the MaxAge was overridden by a rewrite rule.
If you have something like
Code:
RewriteRule /test/test2,php - [E="Cache-Control:max-age=300]
in parent directory of /test/ directory, it will override the max-age in response header.

RewriteRule has higher priority than the response header. Otherwise, the max-age in response header should be respected.
 
Last edited by a moderator:

mistwang

LiteSpeed Staff
#9
Fixed in latest build of 4.2.23, please force reinstall with command
Code:
/usr/local/lsws/admin/misc/lsup.sh -f -v 4.2.23
 
Last edited by a moderator:

anything

Well-Known Member
#10
Fixed in latest build of 4.2.23, please force reinstall with command

/usr/local/lsws/admin/misc/lsup.sh -f -v 4.2.23
thanks for the update.
confirmed fixed

also tested
Code:
Cache Expire Time (seconds) 0
combined with
Code:
Cache-Control: public, max-age=20
and confirmed that it caches for 20 seconds as expected.
 
Last edited by a moderator:
Status
Not open for further replies.
Top