给定示例的Apache2虚拟主机配置
<VirtualHost *:80>
ServerName mywebsite
DocumentRoot ${APACHE_DOCUMENT_ROOT}
# This is because the hostname of the virtual-host serving the content is
# used within the cache key. With the setting set to On virtual-hosts with
# multiple server names or aliases will not produce differently cached
# entities, and instead content will be cached as per the canonical
# hostname.
UseCanonicalName On
# Cache content before mod_deflate
CacheQuickHandler off
SetOutputFilter CACHE
AddOutputFilterByType DEFLATE application/json
# X-Cache header will be added to response with the cache status
CacheHeader on
CacheSocache memcache:${MEMCACHED_URI}
CacheSocacheMaxSize 983040
CacheEnable socache /
<Directory ${APACHE_DOCUMENT_ROOT}>
FallbackResource /index.php
AllowOverride None
</Directory>
</VirtualHost>
在这种情况下,每当请求/products?lang=en
时,都会使用/index.php?lang=en
路径生成缓存键。这意味着/attributes?lang=en
也将具有相同的缓存键。
以下是此特定情况的日志:
[Mon Dec 03 09:02:58 2018] [debug] [pid 18] cache_storage.c(666): [client 172.19.0.1:41618] AH00698: cache: Key for entity /index.php?lang=en is http://mywebsite:80/index.php?lang=en
[Mon Dec 03 09:02:58 2018] [debug] [pid 18] mod_cache_socache.c(496): (70015)Could not find specified socket in poll list.: [client 172.19.0.1:41618] AH02352: Key not found in cache: http://mywebsite:80/index.php?lang=en
[Mon Dec 03 09:02:58 2018] [debug] [pid 18] mod_cache.c(507): [client 172.19.0.1:41618] AH00757: Adding CACHE_SAVE filter for /index.php
[Mon Dec 03 09:02:58 2018] [debug] [pid 18] mod_cache.c(530): [client 172.19.0.1:41618] AH00758: Replacing CACHE with CACHE_SAVE filter for /index.php
[Mon Dec 03 09:02:58 2018] [debug] [pid 18] mod_cache.c(541): [client 172.19.0.1:41618] AH00759: Adding CACHE_REMOVE_URL filter for /index.php
[Mon Dec 03 09:03:00 2018] [debug] [pid 18] mod_cache.c(1348): [client 172.19.0.1:41618] AH00769: cache: Caching url http://mywebsite:80/index.php?lang=en for request /products?lang=en
[Mon Dec 03 09:03:00 2018] [debug] [pid 18] mod_cache.c(1354): [client 172.19.0.1:41618] AH00770: cache: Removing CACHE_REMOVE_URL filter.
[Mon Dec 03 09:03:00 2018] [debug] [pid 18] mod_cache_socache.c(1125): [client 172.19.0.1:41618] AH02387: commit_entity: Headers and body for URL http://mywebsite:80/index.php?lang=en cached for maximum of 1201 seconds.
[Mon Dec 03 09:03:00 2018] [debug] [pid 18] mod_deflate.c(853): [client 172.19.0.1:41618] AH01384: Zlib: Compressed 28116 to 3379 : URL /index.php
172.19.0.1 - - [03/Dec/2018:09:02:58 +0000] "GET /products?lang=en HTTP/1.1" 200 3397 "-" "curl/7.58.0"
如何配置Apache2以生成具有实际请求路径的缓存键?