mirror of
https://github.com/apache/httpd.git
synced 2025-08-01 07:26:57 +03:00
mod_cache: Make CacheEnable and CacheDisable configurable per
directory in addition to per server, making them work from within a LocationMatch. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1080834 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
4
CHANGES
4
CHANGES
@ -2,6 +2,10 @@
|
|||||||
|
|
||||||
Changes with Apache 2.3.12
|
Changes with Apache 2.3.12
|
||||||
|
|
||||||
|
*) mod_cache: Make CacheEnable and CacheDisable configurable per
|
||||||
|
directory in addition to per server, making them work from within
|
||||||
|
a LocationMatch. [Graham Leggett]
|
||||||
|
|
||||||
*) worker, event, prefork: Correct several issues when built as
|
*) worker, event, prefork: Correct several issues when built as
|
||||||
DSOs; most notably, the scoreboard was reinitialized during graceful
|
DSOs; most notably, the scoreboard was reinitialized during graceful
|
||||||
restart, such that processes of the previous generation were not
|
restart, such that processes of the previous generation were not
|
||||||
|
@ -332,17 +332,20 @@
|
|||||||
<name>CacheEnable</name>
|
<name>CacheEnable</name>
|
||||||
<description>Enable caching of specified URLs using a specified storage
|
<description>Enable caching of specified URLs using a specified storage
|
||||||
manager</description>
|
manager</description>
|
||||||
<syntax>CacheEnable <var>cache_type</var> <var>url-string</var></syntax>
|
<syntax>CacheEnable <var>cache_type</var> [<var>url-string</var>]</syntax>
|
||||||
<contextlist><context>server config</context><context>virtual host</context>
|
<contextlist><context>server config</context><context>virtual host</context>
|
||||||
|
<context>directory</context><context>.htaccess</context>
|
||||||
</contextlist>
|
</contextlist>
|
||||||
|
|
||||||
<usage>
|
<usage>
|
||||||
<p>The <directive>CacheEnable</directive> directive instructs
|
<p>The <directive>CacheEnable</directive> directive instructs
|
||||||
<module>mod_cache</module> to cache urls at or below
|
<module>mod_cache</module> to cache urls at or below
|
||||||
<var>url-string</var>. The cache storage manager is specified with the
|
<var>url-string</var>. The cache storage manager is specified with the
|
||||||
<var>cache_type</var> argument. If the <directive>CacheEnable</directive>
|
<var>cache_type</var> argument. The <directive>CacheEnable</directive>
|
||||||
directive is placed inside a <directive type="section">Location</directive>
|
directive can alternatively be placed inside either
|
||||||
directive, the <var>url-string</var> becomes optional.
|
<directive type="section">Location</directive> or
|
||||||
|
<directive type="section">LocationMatch</directive> sections to indicate
|
||||||
|
the content is cacheable.
|
||||||
<var>cache_type</var> <code>disk</code> instructs
|
<var>cache_type</var> <code>disk</code> instructs
|
||||||
<module>mod_cache</module> to use the disk based storage manager
|
<module>mod_cache</module> to use the disk based storage manager
|
||||||
implemented by <module>mod_cache_disk</module>.</p>
|
implemented by <module>mod_cache_disk</module>.</p>
|
||||||
@ -351,13 +354,28 @@ manager</description>
|
|||||||
each possible storage manager will be run until the first one that
|
each possible storage manager will be run until the first one that
|
||||||
actually processes the request. The order in which the storage managers are
|
actually processes the request. The order in which the storage managers are
|
||||||
run is determined by the order of the <directive>CacheEnable</directive>
|
run is determined by the order of the <directive>CacheEnable</directive>
|
||||||
directives in the configuration file.</p>
|
directives in the configuration file. <directive>CacheEnable</directive>
|
||||||
|
directives within <directive type="section">Location</directive> or
|
||||||
|
<directive type="section">LocationMatch</directive> sections are processed
|
||||||
|
before globally defined <directive>CacheEnable</directive> directives.</p>
|
||||||
|
|
||||||
<p>When acting as a forward proxy server, <var>url-string</var> can
|
<p>When acting as a forward proxy server, <var>url-string</var> can
|
||||||
also be used to specify remote sites and proxy protocols which
|
also be used to specify remote sites and proxy protocols which
|
||||||
caching should be enabled for.</p>
|
caching should be enabled for.</p>
|
||||||
|
|
||||||
<example>
|
<example>
|
||||||
|
# Cache content<br />
|
||||||
|
<Location /foo><br />
|
||||||
|
<indent>
|
||||||
|
CacheEnable disk<br />
|
||||||
|
</indent>
|
||||||
|
</Location><br /><br />
|
||||||
|
# Cache regex<br />
|
||||||
|
<LocationMatch foo$><br />
|
||||||
|
<indent>
|
||||||
|
CacheEnable disk<br />
|
||||||
|
</indent>
|
||||||
|
</LocationMatch><br /><br />
|
||||||
# Cache proxied url's<br />
|
# Cache proxied url's<br />
|
||||||
CacheEnable disk /<br /><br />
|
CacheEnable disk /<br /><br />
|
||||||
# Cache FTP-proxied url's<br />
|
# Cache FTP-proxied url's<br />
|
||||||
@ -390,6 +408,7 @@ manager</description>
|
|||||||
<description>Disable caching of specified URLs</description>
|
<description>Disable caching of specified URLs</description>
|
||||||
<syntax>CacheDisable <var>url-string</var> | <var>on</var></syntax>
|
<syntax>CacheDisable <var>url-string</var> | <var>on</var></syntax>
|
||||||
<contextlist><context>server config</context><context>virtual host</context>
|
<contextlist><context>server config</context><context>virtual host</context>
|
||||||
|
<context>directory</context><context>.htaccess</context>
|
||||||
</contextlist>
|
</contextlist>
|
||||||
|
|
||||||
<usage>
|
<usage>
|
||||||
@ -407,11 +426,13 @@ manager</description>
|
|||||||
|
|
||||||
<example><title>Example</title>
|
<example><title>Example</title>
|
||||||
<Location /foo><br />
|
<Location /foo><br />
|
||||||
|
<indent>
|
||||||
CacheDisable on<br />
|
CacheDisable on<br />
|
||||||
|
</indent>
|
||||||
</Location><br />
|
</Location><br />
|
||||||
</example>
|
</example>
|
||||||
|
|
||||||
<p> The <code>no-cache</code> environment variable can be set to
|
<p>The <code>no-cache</code> environment variable can be set to
|
||||||
disable caching on a finer grained set of resources in versions
|
disable caching on a finer grained set of resources in versions
|
||||||
2.2.12 and later.</p>
|
2.2.12 and later.</p>
|
||||||
|
|
||||||
|
95
modules/cache/cache_util.c
vendored
95
modules/cache/cache_util.c
vendored
@ -126,51 +126,58 @@ static int uri_meets_conditions(const apr_uri_t *filter, const int pathlen,
|
|||||||
return !strncmp(filter->path, url->path, pathlen);
|
return !strncmp(filter->path, url->path, pathlen);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static cache_provider_list *get_provider(request_rec *r, struct cache_enable *ent,
|
||||||
|
cache_provider_list *providers)
|
||||||
|
{
|
||||||
|
/* Fetch from global config and add to the list. */
|
||||||
|
cache_provider *provider;
|
||||||
|
provider = ap_lookup_provider(CACHE_PROVIDER_GROUP, ent->type,
|
||||||
|
"0");
|
||||||
|
if (!provider) {
|
||||||
|
/* Log an error! */
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
cache_provider_list *newp;
|
||||||
|
newp = apr_pcalloc(r->pool, sizeof(cache_provider_list));
|
||||||
|
newp->provider_name = ent->type;
|
||||||
|
newp->provider = provider;
|
||||||
|
|
||||||
|
if (!providers) {
|
||||||
|
providers = newp;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
cache_provider_list *last = providers;
|
||||||
|
|
||||||
|
while (last->next) {
|
||||||
|
if (last->provider == provider) {
|
||||||
|
return providers;
|
||||||
|
}
|
||||||
|
last = last->next;
|
||||||
|
}
|
||||||
|
if (last->provider == provider) {
|
||||||
|
return providers;
|
||||||
|
}
|
||||||
|
last->next = newp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return providers;
|
||||||
|
}
|
||||||
|
|
||||||
cache_provider_list *cache_get_providers(request_rec *r,
|
cache_provider_list *cache_get_providers(request_rec *r,
|
||||||
cache_server_conf *conf,
|
cache_server_conf *conf,
|
||||||
apr_uri_t uri)
|
apr_uri_t uri)
|
||||||
{
|
{
|
||||||
|
cache_dir_conf *dconf = dconf = ap_get_module_config(r->per_dir_config, &cache_module);
|
||||||
cache_provider_list *providers = NULL;
|
cache_provider_list *providers = NULL;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* loop through all the cacheenable entries */
|
/* per directory cache disable */
|
||||||
for (i = 0; i < conf->cacheenable->nelts; i++) {
|
if (dconf->disable) {
|
||||||
struct cache_enable *ent =
|
return NULL;
|
||||||
(struct cache_enable *)conf->cacheenable->elts;
|
|
||||||
if (uri_meets_conditions(&ent[i].url, ent[i].pathlen, &uri)) {
|
|
||||||
/* Fetch from global config and add to the list. */
|
|
||||||
cache_provider *provider;
|
|
||||||
provider = ap_lookup_provider(CACHE_PROVIDER_GROUP, ent[i].type,
|
|
||||||
"0");
|
|
||||||
if (!provider) {
|
|
||||||
/* Log an error! */
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
cache_provider_list *newp;
|
|
||||||
newp = apr_pcalloc(r->pool, sizeof(cache_provider_list));
|
|
||||||
newp->provider_name = ent[i].type;
|
|
||||||
newp->provider = provider;
|
|
||||||
|
|
||||||
if (!providers) {
|
|
||||||
providers = newp;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
cache_provider_list *last = providers;
|
|
||||||
|
|
||||||
while (last->next) {
|
|
||||||
last = last->next;
|
|
||||||
}
|
|
||||||
last->next = newp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* then loop through all the cachedisable entries
|
/* global cache disable */
|
||||||
* Looking for urls that contain the full cachedisable url and possibly
|
|
||||||
* more.
|
|
||||||
* This means we are disabling cachedisable url and below...
|
|
||||||
*/
|
|
||||||
for (i = 0; i < conf->cachedisable->nelts; i++) {
|
for (i = 0; i < conf->cachedisable->nelts; i++) {
|
||||||
struct cache_disable *ent =
|
struct cache_disable *ent =
|
||||||
(struct cache_disable *)conf->cachedisable->elts;
|
(struct cache_disable *)conf->cachedisable->elts;
|
||||||
@ -180,6 +187,22 @@ cache_provider_list *cache_get_providers(request_rec *r,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* loop through all the per directory cacheenable entries */
|
||||||
|
for (i = 0; i < dconf->cacheenable->nelts; i++) {
|
||||||
|
struct cache_enable *ent =
|
||||||
|
(struct cache_enable *)dconf->cacheenable->elts;
|
||||||
|
providers = get_provider(r, &ent[i], providers);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* loop through all the global cacheenable entries */
|
||||||
|
for (i = 0; i < conf->cacheenable->nelts; i++) {
|
||||||
|
struct cache_enable *ent =
|
||||||
|
(struct cache_enable *)conf->cacheenable->elts;
|
||||||
|
if (uri_meets_conditions(&ent[i].url, ent[i].pathlen, &uri)) {
|
||||||
|
providers = get_provider(r, &ent[i], providers);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return providers;
|
return providers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
6
modules/cache/cache_util.h
vendored
6
modules/cache/cache_util.h
vendored
@ -164,6 +164,10 @@ typedef struct {
|
|||||||
apr_time_t defex;
|
apr_time_t defex;
|
||||||
/* factor for estimating expires date */
|
/* factor for estimating expires date */
|
||||||
double factor;
|
double factor;
|
||||||
|
/* cache enabled for this location */
|
||||||
|
apr_array_header_t *cacheenable;
|
||||||
|
/* cache disabled for this location */
|
||||||
|
int disable:1;
|
||||||
/* set X-Cache headers */
|
/* set X-Cache headers */
|
||||||
int x_cache:1;
|
int x_cache:1;
|
||||||
int x_cache_detail:1;
|
int x_cache_detail:1;
|
||||||
@ -188,6 +192,8 @@ typedef struct {
|
|||||||
int store_expired_set:1;
|
int store_expired_set:1;
|
||||||
int store_private_set:1;
|
int store_private_set:1;
|
||||||
int store_nostore_set:1;
|
int store_nostore_set:1;
|
||||||
|
int enable_set:1;
|
||||||
|
int disable_set:1;
|
||||||
} cache_dir_conf;
|
} cache_dir_conf;
|
||||||
|
|
||||||
/* A linked-list of authn providers. */
|
/* A linked-list of authn providers. */
|
||||||
|
28
modules/cache/mod_cache.c
vendored
28
modules/cache/mod_cache.c
vendored
@ -1720,6 +1720,9 @@ static void *create_dir_config(apr_pool_t *p, char *dummy)
|
|||||||
|
|
||||||
dconf->stale_on_error = DEFAULT_CACHE_STALE_ON_ERROR;
|
dconf->stale_on_error = DEFAULT_CACHE_STALE_ON_ERROR;
|
||||||
|
|
||||||
|
/* array of providers for this URL space */
|
||||||
|
dconf->cacheenable = apr_array_make(p, 10, sizeof(struct cache_enable));
|
||||||
|
|
||||||
return dconf;
|
return dconf;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1764,6 +1767,12 @@ static void *merge_dir_config(apr_pool_t *p, void *basev, void *addv) {
|
|||||||
new->stale_on_error_set = add->stale_on_error_set
|
new->stale_on_error_set = add->stale_on_error_set
|
||||||
|| base->stale_on_error_set;
|
|| base->stale_on_error_set;
|
||||||
|
|
||||||
|
new->cacheenable = add->enable_set ? apr_array_append(p, base->cacheenable,
|
||||||
|
add->cacheenable) : base->cacheenable;
|
||||||
|
new->enable_set = add->enable_set || base->enable_set;
|
||||||
|
new->disable = (add->disable_set == 0) ? base->disable : add->disable;
|
||||||
|
new->disable_set = add->disable_set || base->disable_set;
|
||||||
|
|
||||||
return new;
|
return new;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1993,6 +2002,7 @@ static const char *add_cache_enable(cmd_parms *parms, void *dummy,
|
|||||||
const char *type,
|
const char *type,
|
||||||
const char *url)
|
const char *url)
|
||||||
{
|
{
|
||||||
|
cache_dir_conf *dconf = (cache_dir_conf *)dummy;
|
||||||
cache_server_conf *conf;
|
cache_server_conf *conf;
|
||||||
struct cache_enable *new;
|
struct cache_enable *new;
|
||||||
|
|
||||||
@ -2023,7 +2033,15 @@ static const char *add_cache_enable(cmd_parms *parms, void *dummy,
|
|||||||
conf =
|
conf =
|
||||||
(cache_server_conf *)ap_get_module_config(parms->server->module_config,
|
(cache_server_conf *)ap_get_module_config(parms->server->module_config,
|
||||||
&cache_module);
|
&cache_module);
|
||||||
new = apr_array_push(conf->cacheenable);
|
|
||||||
|
if (parms->path) {
|
||||||
|
new = apr_array_push(dconf->cacheenable);
|
||||||
|
dconf->enable_set = 1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
new = apr_array_push(conf->cacheenable);
|
||||||
|
}
|
||||||
|
|
||||||
new->type = type;
|
new->type = type;
|
||||||
if (apr_uri_parse(parms->pool, url, &(new->url))) {
|
if (apr_uri_parse(parms->pool, url, &(new->url))) {
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -2040,6 +2058,7 @@ static const char *add_cache_enable(cmd_parms *parms, void *dummy,
|
|||||||
static const char *add_cache_disable(cmd_parms *parms, void *dummy,
|
static const char *add_cache_disable(cmd_parms *parms, void *dummy,
|
||||||
const char *url)
|
const char *url)
|
||||||
{
|
{
|
||||||
|
cache_dir_conf *dconf = (cache_dir_conf *)dummy;
|
||||||
cache_server_conf *conf;
|
cache_server_conf *conf;
|
||||||
struct cache_disable *new;
|
struct cache_disable *new;
|
||||||
|
|
||||||
@ -2065,6 +2084,13 @@ static const char *add_cache_disable(cmd_parms *parms, void *dummy,
|
|||||||
conf =
|
conf =
|
||||||
(cache_server_conf *)ap_get_module_config(parms->server->module_config,
|
(cache_server_conf *)ap_get_module_config(parms->server->module_config,
|
||||||
&cache_module);
|
&cache_module);
|
||||||
|
|
||||||
|
if (parms->path) {
|
||||||
|
dconf->disable = 1;
|
||||||
|
dconf->disable_set = 1;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
new = apr_array_push(conf->cachedisable);
|
new = apr_array_push(conf->cachedisable);
|
||||||
if (apr_uri_parse(parms->pool, url, &(new->url))) {
|
if (apr_uri_parse(parms->pool, url, &(new->url))) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
Reference in New Issue
Block a user