Index: mod_disk_cache.c
===================================================================
--- mod_disk_cache.c	(revision 470455)
+++ mod_disk_cache.c	(working copy)
@@ -1303,7 +1303,8 @@
                                                    &core_module);
 #endif  
 
-    flags = APR_CREATE | APR_WRITE | APR_READ | APR_BINARY | APR_BUFFERED | APR_EXCL | APR_TRUNCATE;
+//    flags = APR_CREATE | APR_WRITE | APR_READ | APR_BINARY | APR_BUFFERED | APR_EXCL | APR_TRUNCATE;
+    flags = APR_CREATE | APR_WRITE | APR_READ | APR_BINARY | APR_EXCL | APR_TRUNCATE; //GG apr_file_seek does not work with APR_BUFFERED
 #if APR_HAS_SENDFILE
     flags |= ((pdconf->enable_sendfile == ENABLE_SENDFILE_OFF)
              ? 0 : APR_SENDFILE_ENABLED);
@@ -1457,6 +1458,7 @@
 static apr_status_t store_disk_header(disk_cache_object_t *dobj,
                                        request_rec *r, cache_info *info)
 {
+//    if ( dobj->initial_size < 0) return APR_SUCCESS; //do not store incorrect size. GG
     disk_cache_format_t format = DISK_FORMAT_VERSION;
     struct iovec iov[3];
     int niov;
@@ -1646,6 +1648,7 @@
     disk_cache_object_t *dobj = (disk_cache_object_t *) h->cache_obj->vobj;
     disk_cache_conf *conf = ap_get_module_config(r->server->module_config,
                                                  &disk_cache_module);
+    int is_eos = FALSE;
 
     dobj->store_body_called++;
     
@@ -1707,6 +1710,9 @@
         apr_size_t length, written;
         apr_off_t offset = 0;
 
+		// first check if it's EOS
+		if (APR_BUCKET_IS_EOS(e)) is_eos = TRUE;
+		
         /* try write all data buckets to the cache, except for metadata buckets */
         if(!APR_BUCKET_IS_METADATA(e)) {
 
@@ -1798,7 +1804,7 @@
              * a hole in the cached data.
              */
             else {
-
+				is_eos = FALSE; //GG I think in this case we should not write the headers
                 /* mark the write as having failed */
                 ap_log_error(APLOG_MARK, APLOG_ERR, rv, r->server,
                              "disk_cache: Error when writing cache file for "
@@ -1849,7 +1855,7 @@
 
     
     /* Drop out here if this wasn't the end */
-    if (!APR_BUCKET_IS_EOS(APR_BRIGADE_LAST(bb))) {
+    if (!is_eos) {
         return APR_SUCCESS;
     }
 
@@ -1876,6 +1882,7 @@
     if (dobj->initial_size < 0) {
         /* Update header information now that we know the size */
         dobj->initial_size = dobj->file_size;
+		dobj->disk_info.file_size = dobj->file_size; //GG added. required?
         rv = store_headers(h, r, &(h->cache_obj->info));
         if (rv != APR_SUCCESS) {
             file_cache_errorcleanup(dobj, r);
