Hi all,

I have two changes to the mod_disk_cache on-disk structure that I plan to make, and to avoid gratuitous format version bumping, I plan to make this format change in one go, and then apply each implementation separately.

The changes are:

- Fix the problem that updates to an entry by mod_disk_cache aren't atomic, without using locks.

To fix this, the inode and device numbers for the body file are embedded in the header file, and when the header and body files are read in, the ident so saved in the header is checked against the real ident of the body (in a stat we're already doing anyway to get the body size). When the check fails, we know that our attempt to read in the header and open the body file have failed due to the race condition, and we should try open the files again.

- Add flags to indicate whether the body is included, and whether we've attempted to cache a HEAD request.

Sometimes, we are asked to cache responses that officially have no body (eg 204 No Content), or potentially HEAD requests that should have a body, but don't. In these cases, we end up saving a zero byte body file, which takes up one extra inode. The flag indicates that no body is included with this entry, and that mod_disk_cache shouldn't look for one. This is useful when attempts are made to cache service calls, where the result of the call is the result code, or when the result of the call arrives in headers only.

The format change looks like this:

Index: modules/cache/mod_disk_cache.h
===================================================================
--- modules/cache/mod_disk_cache.h      (revision 1002189)
+++ modules/cache/mod_disk_cache.h      (working copy)
@@ -17,12 +17,14 @@
 #ifndef MOD_DISK_CACHE_H
 #define MOD_DISK_CACHE_H

+#include "apr_file_io.h"
+
 /*
  * include for mod_disk_cache: Disk Based HTTP 1.1 Cache.
  */

-#define VARY_FORMAT_VERSION 3
-#define DISK_FORMAT_VERSION 4
+#define VARY_FORMAT_VERSION 5
+#define DISK_FORMAT_VERSION 6

 #define CACHE_HEADER_SUFFIX ".header"
 #define CACHE_DATA_SUFFIX   ".data"
@@ -49,6 +51,12 @@
     apr_time_t expire;
     apr_time_t request_time;
     apr_time_t response_time;
+ /* The ident of the body file, so we can test the body matches the header */
+    apr_ino_t inode;
+    apr_dev_t device;
+    /* Does this cached request have a body? */
+    int has_body;
+    int header_only;
 } disk_cache_info_t;

 typedef struct {

Regards,
Graham
--

Reply via email to