文档章节

Apache Mod cache usage and configuration

stubhub
 stubhub
发布于 2014/07/01 12:06
字数 612
阅读 12
收藏 0

Apache mod cache

 

Two files will be created, containing cache-data and cache-header

 

To store items in the cache, mod_cache_disk creates a 22 character hash of the URL being requested. This hash incorporates the hostname, protocol, port, path and any CGI arguments to the URL, as well aselements defined by the Vary header to ensure that multiple URLs do not collide with one another. This hash is used as a prefix for the naming of the files specific to that URL within the cache

 

Apache will check cache freshness by comparing current request headers and cached headers

 

 

 

Cache or not cache

  1. Caching must be enabled forthis URL. See the CacheEnable and CacheDisable directives.

  2. The response must have a HTTPstatus code of 200, 203, 300, 301 or 410.

  3. The request must be a HTTP GETrequest.

  4. If the response contains an"Authorization:" header, it must also contain an"s-maxage", "must-revalidate" or "public" optionin the "Cache-Control:" header, or it won't be cached.

  5. If the URL included a querystring (e.g. from a HTML form GET method) it will not be cached unless the response specifies an explicit expiration by including an "Expires:"header or the max-age or s-maxage directive of the "Cache-Control:"header, as per RFC2616 sections 13.9 and 13.2.1.

  6. If the response has a status of200 (OK), the response must also include at least one of the "Etag","Last-Modified" or the "Expires" headers, or the max-age ors-maxage directive of the "Cache-Control:" header, unless the CacheIgnoreNoLastModdirective has been used to require otherwise.

  7. If the response includes the"private" option in a "Cache-Control:" header, it will notbe stored unless the CacheStorePrivate has been used to require otherwise.

  8. Likewise, if the responseincludes the "no-store" option in a "Cache-Control:"header, it will not be stored unless the CacheStoreNoStore has been used.

  9. A response will not be storedif it includes a "Vary:" header containing the match-all"*".

 

See http://httpd.apache.org/docs/trunk/caching.html

 

 

Concurrency issue:

We found that when multi thread isaccessing apache cache, there are lot of 304 response returned. When we test itby single thread, we are not seeing this problem though. This is related tocache lock.  

 

 

 

The cache lock is a mechanism to avoid overwhelming the back end. When cache expires, a lot of requests will hit backend concurrently, which creates load spike. Cache lock is an indicate that cache is being updated and request should not go to backend. The parameterCacheLockMaxAge determines how long the cache should be locked. Its value should be governed by how fast cache reload can be performed.

 

The frequency of seeing 304 is highly dependson the parameter CacheLockMaxAge. The larger value, the more frequent we willsee 304. If we disable cacheLock, we will not see 304 anymore.

 

 

 

Normally we want different cache strategyto be applied to different url

We allow a path string

Eg:  CacheEnable disk /solr/

 

Note that apache cache does not support pattern match in url, so any * in the url is not interpreted correctly. So if we are to disable caching for certain url pattern

SetEnvIf REQUEST_URI admin no-cache

 

 

Debug:

CacheHeader on

CacheDetailHeader on

Response contains header: X-Cache andX-Cache-detail

Eg:

X-Cache

MISS from www.mydomain.com

X-Cache-Detail

"cache miss: attempting entity  save" from www.mydomain.com

 

This let you have a clear picture ofwhether cache hits the reason if not hit

 

Enable logging

[httpd.conf]

LogLevel debug

 

CustomLog logs/cached-requests.log commonenv=cache-hit

CustomLog logs/uncached-requests.log commonenv=cache-miss

CustomLog logs/revalidated-requests.logcommon env=cache-revalidate

CustomLog logs/invalidated-requests.logcommon env=cache-invalidate

 

LogFormat "%{cache-status}e "cachelog

 

CustomLog logs/cache.log cachelog

 

 

Sample configuration

CacheRoot /tmp/cache

CacheLastModifiedFactor 0.5

CacheMaxExpire 300

CacheIgnoreHeaders Set-Cookie

CacheIgnoreNoLastMod on

CacheDefaultExpire 300

CacheIgnoreCacheControl on

 

CacheEnable disk /test/

CacheDirLevels 5

CacheDirLength 3

CacheMaxFileSize 1000000

CacheMinFileSize 64

#CacheLock on

#CacheLockPath /tmp/mod_cache-lock

 

SetEnvIf REQUEST_URI admin no-cache


本文转载自:http://shadowisper.blog.51cto.com/3189863/1433010

stubhub
粉丝 1
博文 10
码字总数 2015
作品 0
浦东
私信 提问
apache2.2升级到apache2.4问题

1、[lbmethod_heartbeat:notice] [pid 19699] AH02282: No slotmem from mod_heartmonitor 解决办法:注释掉mod_lbmethod_heartbeat.so #LoadModule lbmethod_heartbeat_module modules/mod......

庆沉
2015/12/21
35
0
第 3 章 Apache httpd

LAMP 目录 3.1. Install 3.2. Module 3.3. 设置Apache实现防盗连 3.4. .htaccess 3.5. Error Prompt $ sudo apt-get install apache2$ sudo apt-get install apache2-mpm-worker netkiller@L......

玄学酱
2018/01/01
0
0
apache多站点如何建设以下为httpd.conf

# # This is the main Apache HTTP server configuration file. It contains the # configuration directives that give the server its instructions. # See for detailed information. # I......

一直很硬
2011/06/13
2.4K
2
IE10访问apache 2.4会奇慢的解决办法

Windows版的apache 2.4. IE10访问apache 2.4会特别慢。有时Apache挂起了。只好重新开apache,但是重开后,也会好景不长,刚处理几个请求,就又变得奇慢了。Firefox就没有问题。其他浏览器没有...

mikelij
2013/06/29
0
0
求助 未知问题 未开启伪装静态 未设置 .htacess 但是可以实现

先上截图 目录结构 httpdconf配置文件 # # This is the main Apache HTTP server configuration file. It contains the # configuration directives that give the server its instructions......

jingdor
2013/02/19
316
7

没有更多内容

加载失败,请刷新页面

加载更多

springboot初探---spring-boot-starter-web究竟干了啥

上一篇已经简单介绍了启动类的部分,这一篇主要讨论一下springboot引入的哪些依赖 我们都知道想用springboot做一个web应用,首先要做的是引入相关依赖,两步操作: 1、添加spring-boot-start...

计算机狼
32分钟前
5
0
基于Rocket.chat搭建内网聊天系统(使用docker,本机不需要安装meteor)

您可能不希望使用标准的Docker命令,而是希望对部署进行更多的自动化管理。这就是使用Docker-compose可能会派上用场的地方。 确保您已安装Docker和Docker-compose并且可以正常运行。 docker...

吴伟祥
34分钟前
6
0
conda 更新源

更新conda 源为阿里源 conda config --add channels http://mirrors.aliyun.com/pypi/simple conda config --set show_channel_urls yes 阿里云: http://mirrors.aliyun.com/pypi/simple/ 豆......

Mr_Tea伯奕
34分钟前
4
0
java 泛型使用

每次写泛型方法都翻下百度,还是自己记录下把。 1、定义一个泛型方法,使用传入参数类型来传递泛型。这种用法在封装json序列化工具类应该会用到。 List<xxx> aa = getList(xxx.class);pr...

朝如青丝暮成雪
38分钟前
6
0
深入了解Java模板引擎Freemarker

前言 常用的Java模板引擎包括:JSP、Freemarker、Thymeleaf、Velocity,从Github上查阅到这几款主流的模板引擎的性能的对比,总体上看,JSP、Freemarker、Thymeleaf、Velocity在性能上差别不...

code-ortaerc
39分钟前
8
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部