comparison src/http/ngx_http_file_cache.c @ 5960:e9effef98874

Upstream: use_temp_path parameter of proxy_cache_path and friends. When set to "off", temporary files for cacheable responses will be stored inside cache directory.
author Valentin Bartenev <vbart@nginx.com>
date Fri, 26 Dec 2014 16:22:59 +0300
parents f7584d7c0ccb
children 99639bfdfa2a
comparison
equal deleted inserted replaced
5959:f7584d7c0ccb 5960:e9effef98874
1933 1933
1934 if (name->len < 2 * NGX_HTTP_CACHE_KEY_LEN) { 1934 if (name->len < 2 * NGX_HTTP_CACHE_KEY_LEN) {
1935 return NGX_ERROR; 1935 return NGX_ERROR;
1936 } 1936 }
1937 1937
1938 /*
1939 * Temporary files in cache have a suffix consisting of a dot
1940 * followed by 10 digits.
1941 */
1942
1943 if (name->len >= 2 * NGX_HTTP_CACHE_KEY_LEN + 1 + 10
1944 && name->data[name->len - 10 - 1] == '.')
1945 {
1946 return NGX_OK;
1947 }
1948
1938 if (ctx->size < (off_t) sizeof(ngx_http_file_cache_header_t)) { 1949 if (ctx->size < (off_t) sizeof(ngx_http_file_cache_header_t)) {
1939 ngx_log_error(NGX_LOG_CRIT, ctx->log, 0, 1950 ngx_log_error(NGX_LOG_CRIT, ctx->log, 0,
1940 "cache file \"%s\" is too small", name->data); 1951 "cache file \"%s\" is too small", name->data);
1941 return NGX_ERROR; 1952 return NGX_ERROR;
1942 } 1953 }
2061 time_t inactive; 2072 time_t inactive;
2062 ssize_t size; 2073 ssize_t size;
2063 ngx_str_t s, name, *value; 2074 ngx_str_t s, name, *value;
2064 ngx_int_t loader_files; 2075 ngx_int_t loader_files;
2065 ngx_msec_t loader_sleep, loader_threshold; 2076 ngx_msec_t loader_sleep, loader_threshold;
2066 ngx_uint_t i, n; 2077 ngx_uint_t i, n, use_temp_path;
2067 ngx_array_t *caches; 2078 ngx_array_t *caches;
2068 ngx_http_file_cache_t *cache, **ce; 2079 ngx_http_file_cache_t *cache, **ce;
2069 2080
2070 cache = ngx_pcalloc(cf->pool, sizeof(ngx_http_file_cache_t)); 2081 cache = ngx_pcalloc(cf->pool, sizeof(ngx_http_file_cache_t));
2071 if (cache == NULL) { 2082 if (cache == NULL) {
2074 2085
2075 cache->path = ngx_pcalloc(cf->pool, sizeof(ngx_path_t)); 2086 cache->path = ngx_pcalloc(cf->pool, sizeof(ngx_path_t));
2076 if (cache->path == NULL) { 2087 if (cache->path == NULL) {
2077 return NGX_CONF_ERROR; 2088 return NGX_CONF_ERROR;
2078 } 2089 }
2090
2091 use_temp_path = 1;
2079 2092
2080 inactive = 600; 2093 inactive = 600;
2081 loader_files = 100; 2094 loader_files = 100;
2082 loader_sleep = 50; 2095 loader_sleep = 50;
2083 loader_threshold = 200; 2096 loader_threshold = 200;
2133 invalid_levels: 2146 invalid_levels:
2134 2147
2135 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, 2148 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2136 "invalid \"levels\" \"%V\"", &value[i]); 2149 "invalid \"levels\" \"%V\"", &value[i]);
2137 return NGX_CONF_ERROR; 2150 return NGX_CONF_ERROR;
2151 }
2152
2153 if (ngx_strncmp(value[i].data, "use_temp_path=", 14) == 0) {
2154
2155 if (ngx_strcmp(&value[i].data[14], "on") == 0) {
2156 use_temp_path = 1;
2157
2158 } else if (ngx_strcmp(&value[i].data[14], "off") == 0) {
2159 use_temp_path = 0;
2160
2161 } else {
2162 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2163 "invalid use_temp_path value \"%V\", "
2164 "it must be \"on\" or \"off\"",
2165 &value[i]);
2166 return NGX_CONF_ERROR;
2167 }
2168
2169 continue;
2138 } 2170 }
2139 2171
2140 if (ngx_strncmp(value[i].data, "keys_zone=", 10) == 0) { 2172 if (ngx_strncmp(value[i].data, "keys_zone=", 10) == 0) {
2141 2173
2142 name.data = value[i].data + 10; 2174 name.data = value[i].data + 10;
2272 2304
2273 2305
2274 cache->shm_zone->init = ngx_http_file_cache_init; 2306 cache->shm_zone->init = ngx_http_file_cache_init;
2275 cache->shm_zone->data = cache; 2307 cache->shm_zone->data = cache;
2276 2308
2309 cache->use_temp_path = use_temp_path;
2310
2277 cache->inactive = inactive; 2311 cache->inactive = inactive;
2278 cache->max_size = max_size; 2312 cache->max_size = max_size;
2279 2313
2280 caches = (ngx_array_t *) (confp + cmd->offset); 2314 caches = (ngx_array_t *) (confp + cmd->offset);
2281 2315