summaryrefslogtreecommitdiffhomepage
path: root/src/http/ngx_http_file_cache.c (follow)
AgeCommit message (Collapse)AuthorFilesLines
2017-07-26Cache: fixed max_size on win32.Ruslan Ermilov1-0/+1
2017-05-18Cache: ignore long locked entries during forced expire.Dmitry Volyntsev1-11/+42
Abnormally exited workers may leave locked cache entries, this can result in the cache size on disk exceeding max_size and shared memory exhaustion. This change mitigates the issue by ignoring locked entries during forced expire. It also increases the visibility of the problem by logging such entries.
2017-04-12Use ngx_calloc_buf() where appropriate.Ruslan Ermilov1-1/+1
2017-02-10Upstream: proxy_cache_background_update and friends.Roman Arutyunyan1-1/+1
The directives enable cache updates in subrequests.
2016-12-22Cache: support for stale-while-revalidate and stale-if-error.Roman Arutyunyan1-0/+8
Previously, there was no way to enable the proxy_cache_use_stale behavior by reading the backend response. Now, stale-while-revalidate and stale-if-error Cache-Control extensions (RFC 5861) are supported. They specify, how long a stale response can be used when a cache entry is being updated, or in case of an error.
2016-12-24Win32: fixed some warnings reported by Borland C.Maxim Dounin1-3/+3
Most notably, warning W8012 (comparing signed and unsigned values) reported in multiple places where an unsigned value of small type (e.g., u_short) is promoted to an int and compared to an unsigned value. Warning W8072 (suspicious pointer arithmetic) disabled, it is reported when we increment base pointer in ngx_shm_alloc().
2016-11-03Cache: prefix-based temporary files.Maxim Dounin1-32/+13
On Linux, the rename syscall can be slow due to a global file system lock, acquired for the entire rename operation, unless both old and new files are in the same directory. To address this temporary files are now created in the same directory as the expected resulting cache file when using the "use_temp_path=off" parameter. This change mostly reverts 99639bfdfa2a and 3281de8142f5, restoring the behaviour as of a9138c35120d (with minor changes).
2016-10-13Cache: cache manager debugging.Ruslan Ermilov1-9/+23
2016-10-05Cache: cache manager limits.Dmitry Volyntsev1-9/+94
The new parameters "manager_files", "manager_sleep" and "manager_threshold" were added to proxy_cache_path and friends. Note that ngx_path_manager_pt was changed to return ngx_msec_t instead of time_t (API change).
2016-07-06Use NGX_MAX_PATH_LEVEL where appropriate.Ruslan Ermilov1-5/+5
The macro was unused since 0.7.44.
2016-05-16Cache: fixed updating bypassed cached errors (ticket #827).Maxim Dounin1-0/+1
2016-03-31Fixed logging with variable field width.Sergey Kandaurov1-1/+1
2016-03-23Cache: fixed slots accounting error introduced in c9d680b00744.Dmitry Volyntsev1-2/+2
2016-03-18Cache: added watermark to reduce IO load when keys_zone is full.Dmitry Volyntsev1-5/+32
When a keys_zone is full then each next request to the cache is penalized. That is, the cache has to evict older files to get a slot from the keys_zone synchronously. The patch introduces new behavior in this scenario. Manager will try to maintain available free slots in the keys_zone by cleaning old files in the background.
2016-03-18Cache: report error if slab allocator fails during cache loading.Dmitry Volyntsev1-0/+6
2016-03-18Threads: task pointer stored in ngx_file_t.Maxim Dounin1-2/+3
This simplifies the interface of the ngx_thread_read() function. Additionally, most of the thread operations now explicitly set file->thread_task, file->thread_handler and file->thread_ctx, to facilitate use of thread operations in other places. (Potential problems remain with sendfile in threads though - it uses file->thread_handler as set in ngx_output_chain(), and it should not be overwritten to an incompatible one.) In collaboration with Valentin Bartenev.
2015-09-11Cache: check the whole cache key in addition to hashes.Maxim Dounin1-2/+19
This prevents a potential attack that discloses cached data if an attacker will be able to craft a hash collision between some cache key the attacker is allowed to access and another cache key with protected data. See http://mailman.nginx.org/pipermail/nginx-devel/2015-September/007288.html. Thanks to Gena Makhomed and Sergey Brester.
2015-04-01Cache: added support for reading of the header in thread pools.Valentin Bartenev1-19/+105
2015-03-14Added support for offloading read() in thread pools.Valentin Bartenev1-1/+1
2015-03-02Cache: do not inherit last_modified and etag from stale response.Roman Arutyunyan1-2/+0
When replacing a stale cache entry, its last_modified and etag could be inherited from the old entry if the response code is not 200 or 206. Moreover, etag could be inherited with any response code if it's missing in the new response. As a result, the cache entry is left with invalid last_modified or etag which could lead to broken revalidation. For example, when a file is deleted from backend, its last_modified is copied to the new 404 cache entry and is used later for revalidation. Once the old file appears again with its original timestamp, revalidation succeeds and the cached 404 response is sent to client instead of the file. The problem appeared with etags in 44b9ab7752e3 (1.7.3) and affected last_modified in 1573fc7875fa (1.7.9).
2015-02-17Cache: reduced diffs to the plus version of nginx.Ruslan Ermilov1-6/+4
No functional changes.
2015-02-02Cache: added temp_path to file cache.Roman Arutyunyan1-14/+48
If use_temp_path is set to off, a subdirectory "temp" is created in the cache directory. It's used instead of proxy_temp_path and friends for caching upstream response.
2014-12-26Upstream: use_temp_path parameter of proxy_cache_path and friends.Valentin Bartenev1-1/+35
When set to "off", temporary files for cacheable responses will be stored inside cache directory.
2014-12-26Cache: update variant while setting header.Valentin Bartenev1-35/+57
Some parts of code related to handling variants of a resource moved into a separate function that is called earlier. This allows to use cache file name as a prefix for temporary file in the following patch.
2014-12-22Upstream: added variables support to proxy_cache and friends.Valentin Bartenev1-1/+13
2014-11-26Cache: send conditional requests only for cached 200/206 responses.Piotr Sikora1-0/+2
RFC7232 says: The 304 (Not Modified) status code indicates that a conditional GET or HEAD request has been received and would have resulted in a 200 (OK) response if it were not for the fact that the condition evaluated to false. which means that there is no reason to send requests with "If-None-Match" and/or "If-Modified-Since" headers for responses cached with other status codes. Also, sending conditional requests for responses cached with other status codes could result in a strange behavior, e.g. upstream server returning 304 Not Modified for cached 404 Not Found responses, etc. Signed-off-by: Piotr Sikora <piotr@cloudflare.com>
2014-12-02Cache: proper wakeup of subrequests.Maxim Dounin1-2/+6
In case of a cache lock timeout and in the aio handler we now call r->write_event_handler() instead of a connection write handler, to make sure to run appropriate subrequest. Previous code failed to run inactive subrequests and hence resulted in suboptimal behaviour, see report by Yichun Zhang: http://mailman.nginx.org/pipermail/nginx-devel/2013-October/004435.html (Infinite hang claimed in the report seems impossible without 3rd party modules, as subrequests will be eventually woken up by the postpone filter.)
2014-12-02Upstream: improved subrequest logging.Maxim Dounin1-12/+31
To ensure proper logging make sure to set current_request in all event handlers, including resolve, ssl handshake, cache lock wait timer and aio read handlers. A macro ngx_http_set_log_request() introduced to simplify this.
2014-11-18Cache: proxy_cache_lock_age and friends.Roman Arutyunyan1-9/+22
Once this age is reached, the cache lock is discarded and another request can acquire the lock. Requests which failed to acquire the lock are not allowed to cache the response.
2014-11-05Cache: removed dead store in ngx_http_file_cache_vary_header().Maxim Dounin1-1/+0
Found by Clang Static Analyzer.
2014-10-27Cache: normalization of some Vary headers.Maxim Dounin1-2/+66
Spaces in Accept-Charset, Accept-Encoding, and Accept-Language headers are now ignored. As per syntax of these headers spaces can only appear in places where they are optional.
2014-10-27Cache: multiple variants of a resource now can be stored.Maxim Dounin1-3/+77
If a variant stored can't be used to respond to a request, the variant hash is used as a secondary key. Additionally, if we previously switched to a secondary key, while storing a response to cache we check if the variant hash still apply. If not, we switch back to the original key, to handle cases when Vary changes.
2014-10-27Cache: c->reading flag introduced.Maxim Dounin1-1/+4
It replaces c->buf in checks in ngx_http_file_cache_open(), making it possible to reopen the file without clearing c->buf. No functional changes.
2014-10-27Cache: hash of Vary headers now stored in cache.Maxim Dounin1-0/+135
To cache responses with Vary, we now calculate hash of headers listed in Vary, and return the response from cache only if new request headers match. As of now, only one variant of the same resource can be stored in cache.
2014-09-05Upstream: suppressed the file cache slab allocator error messages.Roman Arutyunyan1-0/+4
The messages "ngx_slab_alloc() failed: no memory in cache keys zone" from the file cache slab allocator are suppressed since the allocation is likely to succeed after the forced expiration of cache nodes. The second allocation failure is reported.
2014-06-26Cache: ETag now saved into cache header.Maxim Dounin1-0/+12
2014-06-26Cache: version in cache files.Maxim Dounin1-1/+10
This allows to change the structure of cache files without spamming logs with false alerts.
2014-06-04Core: added ngx_slab_calloc() and ngx_slab_calloc_locked().Ruslan Ermilov1-16/+6
These functions return zeroed memory, analogous to ngx_pcalloc().
2014-04-30Cache: added ngx_quit check to ngx_http_file_cache_expire().Maxim Dounin1-0/+5
While managing big caches it is possible that expiring old cache items in ngx_http_file_cache_expire() will take a while. Added a check for ngx_quit / ngx_terminate to make sure cache manager can be terminated while in ngx_http_file_cache_expire().
2013-11-18Upstream: cache revalidation with conditional requests.Maxim Dounin1-0/+111
The following new directives are introduced: proxy_cache_revalidate, fastcgi_cache_revalidate, scgi_cache_revalidate, uwsgi_cache_revalidate. Default is off. When set to on, they enable cache revalidation using conditional requests with If-Modified-Since for expired cache items. As of now, no attempts are made to merge headers given in a 304 response during cache revalidation with headers previously stored in a cache item. Headers in a 304 response are only used to calculate new validity time of a cache item.
2013-09-04Win32: Borland C compatibility fixes.Maxim Dounin1-1/+1
Several false positive warnings silenced, notably W8012 "Comparing signed and unsigned" (due to u_short values promoted to int), and W8072 "Suspicious pointer arithmetic" (due to large type values added to pointers). With this patch, it's now again possible to compile nginx using bcc32, with options we normally compile on win32 minus ipv6 and ssl.
2013-08-23Cache: lock timeouts are now logged at info level.Maxim Dounin1-2/+1
2013-08-20Backed out f1a91825730a and 7094bd12c1ff.Maxim Dounin1-3/+1
While ngx_get_full_name() might have a bit more descriptive arguments, the ngx_conf_full_name() is generally easier to use when parsing configuration and limits exposure of cycle->prefix / cycle->conf_prefix details.
2013-08-06Replaced ngx_conf_full_name() with ngx_get_full_name().Valentin Bartenev1-1/+3
The ngx_get_full_name() function takes more readable arguments list.
2013-06-05Valgrind: supressed complaints about uninitialized bytes.Maxim Dounin1-0/+2
Valgrind complains if we pass uninitialized memory to a syscall: ==36492== Syscall param sendmsg(msg.msg_iov[0]) points to uninitialised byte(s) ==36492== at 0x6B5E6A: sendmsg (in /usr/lib/system/libsystem_kernel.dylib) ==36492== by 0x10004288E: ngx_signal_worker_processes (ngx_process_cycle.c:527) ==36492== by 0x1000417A7: ngx_master_process_cycle (ngx_process_cycle.c:203) ==36492== by 0x100001F10: main (nginx.c:410) ==36492== Address 0x7fff5fbff71c is on thread 1's stack Even initialization of all members of the structure passed isn't enough, as there is padding which still remains uninitialized and results in Valgrind complaint. Note there is no real problem here as data from uninitialized memory isn't used.
2013-02-19Removed zero termination of shm zone names.Valentin Bartenev1-2/+0
It was added in r2717 and no longer needed since r2721, where the termination was added to ngx_shm_alloc() and ngx_init_zone_pool(). So then it only corrupts error messages about ivalid zones.
2012-02-27Fix of rbtree lookup on hash collisions.Maxim Dounin1-12/+7
Previous code incorrectly assumed that nodes with identical keys are linked together. This might not be true after tree rebalance. Patch by Lanshun Zhou.
2012-02-13Time parsing cleanup.Maxim Dounin1-7/+8
Nuke NGX_PARSE_LARGE_TIME, it's not used since 0.6.30. The only error ngx_parse_time() can currently return is NGX_ERROR, check it explicitly and make sure to cast it to appropriate type (either time_t or ngx_msec_t) to avoid signedness warnings on platforms with unsigned time_t (notably QNX).
2012-01-18Copyright updated.Maxim Konovalov1-0/+1
2011-12-26Fixed build without debug.Maxim Dounin1-2/+2