mod_cache, mod_deflate, mod_expires and a headache

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Guys

I asked about this on IRC but after some digging I think it might be better suited to the mailing list.

I am looking to make use of mod_cache to improve response times on a website. I have mod_cache and mod_disk cache working fine - Content gets cached and recalled from the cache as needed no problem. I have added mod_expires config so that the correct cache control/expires headers are in place so thats working great

Once I add mod_deflate into the mix, things get interesting...

mod_cache is doing what Its configured to do by default on receipt of gzipped data - Lets say my browser sends a request with "Accept-Encoding: gzip, deflate, sdch" then this gets dealt with all nicely and stored in my cache with a "Vary: accept-encoding" header.

So far so good.

Another client connects and sends a request with "Accept-Encoding: gzip, deflate, sdch, br" and as expected, mod_cache stores a separate copy for this because the header is different to the one in my cache. This is where I am falling over...

I dont want to store multiple cached copies of my content so I am trying to cache content uncompressed, and have mod_deflate gzip it before going to the client. Documentation for mod_cache ( see https://httpd.apache.org/docs/trunk/mod/mod_cache.html#finecontrol ) suggests this is indeed possible by using Output filters... 

> # Cache content before optional compression
> CacheQuickHandler off
> AddOutputFilterByType CACHE;DEFLATE text/plain

Great... Except it doesnt do what it suggests.

Doing this results in "CACHE filter was added twice, or was added where the cache has been bypassed and will be ignored" in debug output, and you can see its being compressed before being stored to cache

> [cache:debug] [pid 9497] cache_storage.c(664): [client 10.0.0.20:40156] AH00698: cache: Key for entity /index.php?(null) is https://www.my_website.co.uk:443/index.php?
> [cache:debug] [pid 9497] mod_cache.c(486): [client 10.0.0.20:40156] AH00757: Adding CACHE_SAVE filter for /index.php
> [cache:debug] [pid 9497] mod_cache.c(520): [client 10.0.0.20:40156] AH00759: Adding CACHE_REMOVE_URL filter for /index.php
> [cache:debug] [pid 9497] mod_cache.c(1718): [client 10.0.0.20:40156] AH00777: cache: CACHE filter was added twice, or was added where the cache has been bypassed and will be ignored: /
> [deflate:debug] [pid 9497] mod_deflate.c(849): [client 10.0.0.20:40156] AH01384: Zlib: Compressed 51365 to 12218 : URL /index.php
> [headers:debug] [pid 9497] mod_headers.c(845): AH01502: headers: ap_headers_output_filter()
> [cache:debug] [pid 9497] mod_cache.c(1328): [client 10.0.0.20:40156] AH00769: cache: Caching url: /
> [cache:debug] [pid 9497] mod_cache.c(1334): [client 10.0.0.20:40156] AH00770: cache: Removing CACHE_REMOVE_URL filter.
> [cache_disk:debug] [pid 9497] mod_cache_disk.c(1349): [client 10.0.0.20:40156] AH00737: commit_entity: Headers and body for URL https://www.my_website.co.uk:443/index.php? cached.

I do have a "Workaround" for this in that if I use "SetOutputFilter" and then "AddOutputFilterByType", I sort of get what I want...

> SetOutputFilter CACHE
> AddOutputFilterByType DEFLATE text/html

This does result in correct behaviour in that content is cached before being compressed and as such is only being cached once, however, its now being done before mod_expires has chance to add correct cache control/expiry headers so some things are being considered in-eligable for storing in cache

> [cache:debug] [pid 9607] cache_storage.c(664): [client 10.0.0.20:40174] AH00698: cache: Key for entity /index.php?(null) is https://www.my_website.co.uk:443/index.php?
> [cache:debug] [pid 9607] mod_cache.c(486): [client 10.0.0.20:40174] AH00757: Adding CACHE_SAVE filter for /index.php
> [cache:debug] [pid 9607] mod_cache.c(509): [client 10.0.0.20:40174] AH00758: Replacing CACHE with CACHE_SAVE filter for /index.php
> [cache:debug] [pid 9607] mod_cache.c(520): [client 10.0.0.20:40174] AH00759: Adding CACHE_REMOVE_URL filter for /index.php
> [cache:debug] [pid 9607] mod_cache.c(1328): [client 10.0.0.20:40174] AH00769: cache: Caching url: /
> [cache:debug] [pid 9607] mod_cache.c(1334): [client 10.0.0.20:40174] AH00770: cache: Removing CACHE_REMOVE_URL filter.
> [cache_disk:debug] [pid 9607] mod_cache_disk.c(1349): [client 10.0.0.20:40174] AH00737: commit_entity: Headers and body for URL https://www.my_website.co.uk:443/index.php? cached.
> [deflate:debug] [pid 9607] mod_deflate.c(849): [client 10.0.0.20:40174] AH01384: Zlib: Compressed 51365 to 12218 : URL /index.php
> [headers:debug] [pid 9607] mod_headers.c(845): AH01502: headers: ap_headers_output_filter()
> [cache:debug] [pid 9609] cache_storage.c(664): [client 10.0.0.20:40175] AH00698: cache: Key for entity /index.php?s=bob is https://www.my_website.co.uk:443/index.php?s=bob
> [cache:debug] [pid 9609] mod_cache.c(486): [client 10.0.0.20:40175] AH00757: Adding CACHE_SAVE filter for /index.php
> [cache:debug] [pid 9609] mod_cache.c(509): [client 10.0.0.20:40175] AH00758: Replacing CACHE with CACHE_SAVE filter for /index.php
> [cache:debug] [pid 9609] mod_cache.c(520): [client 10.0.0.20:40175] AH00759: Adding CACHE_REMOVE_URL filter for /index.php
> [cache:debug] [pid 9609] mod_cache.c(1210): [client 10.0.0.20:40175] AH00768: cache: /?s=bob not cached. Reason: Query string present but no explicit expiration time
> [deflate:debug] [pid 9609] mod_deflate.c(849): [client 10.0.0.20:40175] AH01384: Zlib: Compressed 27993 to 6343 : URL /index.php
> [headers:debug] [pid 9609] mod_headers.c(845): AH01502: headers: ap_headers_output_filter()


In sort, I guess what I am asking here seems to be: Is the documentation I mentioned correct for AddOutputFilterByType CACHE;DEFLATE or is this detailed above working as expected? If It is as expected, is there a way I can force mod_expires to be applied before cache so that content is cached correctly?

Slightly sanitized version of my current config:

> # Server version: Apache/2.4.7 (Ubuntu)
> # Server built:   Mar 10 2015 13:05:59
>
>  ServerName www.my_website.co.uk
>  ServerAlias my_website.co.uk 
>  UseCanonicalName On
>  Header always set Strict-Transport-Security "max-age=63072000; includeSubdomains; preload"
>  CacheQuickHandler off
>  SetOutputFilter CACHE
>  AddOutputFilterByType DEFLATE text/html text/plain text/css application/_javascript_ application/rss+xml
>  
>  CacheRoot /var/cache/apache2/mod_cache_disk/my_website.co.uk
>  CacheEnable disk /
>  CacheDirLevels 2
>  CacheDirLength 1
>  CacheMaxFileSize 2000000
>  CacheIgnoreNoLastMod On
>  CacheIgnoreCacheControl On
>  CacheDefaultExpire 7200
>  CacheLastModifiedFactor 0.5
>  CacheIgnoreHeaders Set-Cookie
>  CacheHeader on
>  CacheLock on
>  ExpiresActive on
>  ExpiresDefault "access plus 1 week"
>  ExpiresByType text/html "access plus 2 hours"
>  FileETag All


Any help that can be offered would be greatly appreciated :)

Simon

[Index of Archives]     [Open SSH Users]     [Linux ACPI]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Squid]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux