Updated Branches: refs/heads/master 80d1f32e8 -> e2aff41f8
TS-621 Allow caching of empty docs (currently only if a header Content-Length: 0 is in the response). New config option is named proxy.config.http.cache.allow_empty_doc, and is disabled by default. We are aware this doesn't fully fix the problem, but is "good enough" for now. Reviews and minor cosmetic cleanup changes: James and Leif. Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/e2aff41f Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/e2aff41f Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/e2aff41f Branch: refs/heads/master Commit: e2aff41f8d68144a0e90b1412c6006b784769af4 Parents: 80d1f32 Author: weijin <[email protected]> Authored: Fri Apr 12 15:23:46 2013 -0600 Committer: Leif Hedstrom <[email protected]> Committed: Fri Apr 12 15:23:46 2013 -0600 ---------------------------------------------------------------------- CHANGES | 4 ++++ iocore/cache/Cache.cc | 12 ++++++++++++ iocore/cache/CacheWrite.cc | 20 ++++++++++++++++---- iocore/cache/P_CacheInternal.h | 3 +++ iocore/cache/P_CacheVol.h | 2 +- mgmt/RecordsConfig.cc | 4 ++++ proxy/config/records.config.default.in | 3 +++ 7 files changed, 43 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/trafficserver/blob/e2aff41f/CHANGES ---------------------------------------------------------------------- diff --git a/CHANGES b/CHANGES index 3444721..dd1dcb5 100644 --- a/CHANGES +++ b/CHANGES @@ -2,6 +2,10 @@ Changes with Apache Traffic Server 3.3.2 + *) [TS-621] Allow caching of empty docs (currently only if a header + Content-Length: 0 is in the response). New config option is named + proxy.config.http.cache.allow_empty_doc, and is disabled by default. + *) [TS-1778] Remove vestigal extensions.config support *) [TS-1806] bogus buffer sizing in CfgContextUtils.cc http://git-wip-us.apache.org/repos/asf/trafficserver/blob/e2aff41f/iocore/cache/Cache.cc ---------------------------------------------------------------------- diff --git a/iocore/cache/Cache.cc b/iocore/cache/Cache.cc index d5ba29f..319aca3 100644 --- a/iocore/cache/Cache.cc +++ b/iocore/cache/Cache.cc @@ -79,6 +79,9 @@ int cache_config_alt_rewrite_max_size = 4096; int cache_config_read_while_writer = 0; char cache_system_config_directory[PATH_NAME_MAX + 1]; int cache_config_mutex_retry_delay = 2; +#ifdef HTTP_CACHE +static int enable_cache_empty_http_doc = 0; +#endif // Globals @@ -458,6 +461,14 @@ CacheVC::set_http_info(CacheHTTPInfo *ainfo) ainfo->object_key_set(earliest_key); // don't know the total len yet } + if (enable_cache_empty_http_doc) { + MIMEField *field = ainfo->m_alt->m_response_hdr.field_find(MIME_FIELD_CONTENT_LENGTH, MIME_LEN_CONTENT_LENGTH); + if (field && !field->value_get_int64()) + f.allow_empty_doc = 1; + else + f.allow_empty_doc = 0; + } else + f.allow_empty_doc = 0; alternate.copy_shallow(ainfo); ainfo->clear(); } @@ -2819,6 +2830,7 @@ ink_cache_init(ModuleVersion v) // # 1 - MMH hash REC_EstablishStaticConfigInt32(url_hash_method, "proxy.config.cache.url_hash_method"); Debug("cache_init", "proxy.config.cache.url_hash_method = %d", url_hash_method); + REC_EstablishStaticConfigInt32(enable_cache_empty_http_doc, "proxy.config.http.cache.allow_empty_doc"); #endif REC_EstablishStaticConfigInt32(cache_config_max_disk_errors, "proxy.config.cache.max_disk_errors"); http://git-wip-us.apache.org/repos/asf/trafficserver/blob/e2aff41f/iocore/cache/CacheWrite.cc ---------------------------------------------------------------------- diff --git a/iocore/cache/CacheWrite.cc b/iocore/cache/CacheWrite.cc index b93839d..5160eff 100644 --- a/iocore/cache/CacheWrite.cc +++ b/iocore/cache/CacheWrite.cc @@ -779,7 +779,11 @@ agg_copy(char *p, CacheVC *vc) } if (vc->f.use_first_key) { - if (doc->data_len()) + if (doc->data_len() +#ifdef HTTP_CACHE + || vc->f.allow_empty_doc +#endif + ) doc->key = vc->earliest_key; else // the vector is being written by itself prev_CacheKey(&doc->key, &vc->earliest_key); @@ -1122,7 +1126,11 @@ CacheVC::openWriteCloseDir(int event, Event *e) // one, two and three or more fragments. This is because for // updates we dont decrement the variable corresponding the old // size of the document - if ((closed == 1) && (total_len > 0)) { + if ((closed == 1) && (total_len > 0 +#ifdef HTTP_CACHE + || f.allow_empty_doc +#endif + )) { DDebug("cache_stats", "Fragment = %d", fragment); switch (fragment) { case 0: CACHE_INCREMENT_DYN_STAT(cache_single_fragment_document_count_stat); break; @@ -1270,10 +1278,14 @@ CacheVC::openWriteClose(int event, Event *e) if (!io.ok()) return openWriteCloseDir(event, e); } - if (closed > 0) { + if (closed > 0 +#ifdef HTTP_CACHE + || f.allow_empty_doc +#endif + ) { if (total_len == 0) { #ifdef HTTP_CACHE - if (f.update) { + if (f.update || f.allow_empty_doc) { return updateVector(event, e); } else { // If we've been CLOSE'd but nothing has been written then http://git-wip-us.apache.org/repos/asf/trafficserver/blob/e2aff41f/iocore/cache/P_CacheInternal.h ---------------------------------------------------------------------- diff --git a/iocore/cache/P_CacheInternal.h b/iocore/cache/P_CacheInternal.h index b65cb65..634a1bc 100644 --- a/iocore/cache/P_CacheInternal.h +++ b/iocore/cache/P_CacheInternal.h @@ -485,6 +485,9 @@ struct CacheVC: public CacheVConnection #ifdef HIT_EVACUATE unsigned int hit_evacuate:1; #endif +#ifdef HTTP_CACHE + unsigned int allow_empty_doc:1; // used for cache empty http document +#endif } f; }; // BTF optimization used to skip reading stuff in cache partition that doesn't contain any http://git-wip-us.apache.org/repos/asf/trafficserver/blob/e2aff41f/iocore/cache/P_CacheVol.h ---------------------------------------------------------------------- diff --git a/iocore/cache/P_CacheVol.h b/iocore/cache/P_CacheVol.h index dc183a7..4df3f0f 100644 --- a/iocore/cache/P_CacheVol.h +++ b/iocore/cache/P_CacheVol.h @@ -423,7 +423,7 @@ Doc::data_len() TS_INLINE int Doc::single_fragment() { - return (total_len && (data_len() == total_len)); + return (data_len() == total_len); } TS_INLINE char * http://git-wip-us.apache.org/repos/asf/trafficserver/blob/e2aff41f/mgmt/RecordsConfig.cc ---------------------------------------------------------------------- diff --git a/mgmt/RecordsConfig.cc b/mgmt/RecordsConfig.cc index 55b0cb8..3185e2c 100644 --- a/mgmt/RecordsConfig.cc +++ b/mgmt/RecordsConfig.cc @@ -629,6 +629,10 @@ RecordElement RecordsConfig[] = { // ################# {RECT_CONFIG, "proxy.config.http.cache.http", RECD_INT, "1", RECU_DYNAMIC, RR_NULL, RECC_INT, "[0-1]", RECA_NULL} , + // Enabling this setting allows the proxy to cache empty documents. This currently requires + // that the response has a Content-Length: header, with a value of "0". + {RECT_CONFIG, "proxy.config.http.cache.allow_empty_doc", RECD_INT, "0", RECU_DYNAMIC, RR_NULL, RECC_NULL, "[0-1]", RECA_NULL } + , {RECT_CONFIG, "proxy.config.http.cache.cluster_cache_local", RECD_INT, "0", RECU_DYNAMIC, RR_NULL, RECC_INT, "[0-1]", RECA_NULL} , {RECT_CONFIG, "proxy.config.http.cache.ignore_client_no_cache", RECD_INT, "1", RECU_DYNAMIC, RR_NULL, RECC_INT, "[0-1]", RECA_NULL} http://git-wip-us.apache.org/repos/asf/trafficserver/blob/e2aff41f/proxy/config/records.config.default.in ---------------------------------------------------------------------- diff --git a/proxy/config/records.config.default.in b/proxy/config/records.config.default.in index 9e396f0..7b39d07 100644 --- a/proxy/config/records.config.default.in +++ b/proxy/config/records.config.default.in @@ -218,6 +218,9 @@ CONFIG proxy.config.http.push_method_enabled INT 0 # cache control # ################# CONFIG proxy.config.http.cache.http INT 1 + # Enabling this setting allows the proxy to cache empty documents. This currently + # requires that the response has a Content-Length: header, with a value of "0". +CONFIG proxy.config.http.cache.allow_empty_doc INT 0 CONFIG proxy.config.http.cache.ignore_client_no_cache INT 1 CONFIG proxy.config.http.cache.ims_on_client_no_cache INT 1 CONFIG proxy.config.http.cache.ignore_server_no_cache INT 0
