diff --git a/cache/include/tango_cache_client.h b/cache/include/tango_cache_client.h index 35f83a1..9d35811 100644 --- a/cache/include/tango_cache_client.h +++ b/cache/include/tango_cache_client.h @@ -5,6 +5,7 @@ #include #include "tfe_future.h" +#include "proxy_cache.h" enum CACHE_ERR_CODE { @@ -63,24 +64,14 @@ enum CACHE_HTTP_HDR_TYPE HDR_CONTENT_NUM, }; -struct put_time_strategy -{ - time_t relative_ttl; //PUT: 缓存最大生存时间;0表示使用配置文件的默认值 - time_t absulote_lastmod;//PUT: -}; -struct get_time_strategy -{ - time_t max_age; //GET: - time_t min_fresh;//GET: -}; struct tango_cache_meta { - const char* url; + const char* url; //缓存:URL;非结构化日志:文件名 const char* std_hdr[HDR_CONTENT_NUM]; //完整头部,如包含"Content-Type:",不要包含换行 const char* other_hdr; //最大长度不能超过1535字节,GET时会原样返回 union{ - struct put_time_strategy put;//TODO - struct get_time_strategy get; + struct response_freshness put;//TODO + struct request_freshness get; }; }; @@ -101,7 +92,7 @@ struct tango_cache_instance *tango_cache_instance_new(struct event_base* evbase, int tango_cache_fetch(struct tango_cache_instance *instance, struct future* future, struct tango_cache_meta *meta); /*UPLOAD接口的API*/ -//完整一次上传;若filename不为空,则输出对象的KEY,当CACHE_OBJECT_KEY_HASH_SWITCH=1开启对文件名哈希时有用 +//完整一次上传;若objectkey不为空,则输出对象的KEY,当CACHE_OBJECT_KEY_HASH_SWITCH=1开启对文件名哈希时有用 //返回0表示成功,<0表示失败;下同 int tango_cache_upload_once_data(struct tango_cache_instance *instance, struct future* future, enum PUT_MEMORY_COPY_WAY way, const char *data, size_t size, diff --git a/cache/tango_cache_client.cpp b/cache/tango_cache_client.cpp index 862414b..8bfefa1 100644 --- a/cache/tango_cache_client.cpp +++ b/cache/tango_cache_client.cpp @@ -209,7 +209,7 @@ struct tango_cache_ctx *tango_cache_update_prepare(struct tango_cache_instance * struct tango_cache_ctx *ctx; char buffer[256]={0}; int other_len; - time_t expires, now; + time_t expires, now, last_modify; if((u_int64_t)instance->statistic.memory_used >= instance->cache_limit_size) { @@ -236,17 +236,18 @@ struct tango_cache_ctx *tango_cache_update_prepare(struct tango_cache_instance * //Expires字段,用于缓存内部判定缓存是否超时 now = time(NULL); - expires = (meta->put.relative_ttl==0||meta->put.relative_ttl>instance->relative_ttl)?instance->relative_ttl:meta->put.relative_ttl; + expires = (meta->put.timeout==0||meta->put.timeout>instance->relative_ttl)?instance->relative_ttl:meta->put.timeout; if(expires_timestamp2hdr_str(now + expires, buffer, 256)) { ctx->headers = curl_slist_append(ctx->headers, buffer); } //Last-Modify字段,用于GET时判定是否新鲜 - if(meta->put.absulote_lastmod == 0) + last_modify = (meta->put.date > meta->put.last_modified)?meta->put.date:meta->put.last_modified; + if(last_modify == 0) { - meta->put.absulote_lastmod = get_gmtime_timestamp(now); + last_modify = get_gmtime_timestamp(now); } - sprintf(buffer, "x-amz-meta-lm: %lu", meta->put.absulote_lastmod); + sprintf(buffer, "x-amz-meta-lm: %lu", last_modify); ctx->headers = curl_slist_append(ctx->headers, buffer); //列表中支持的标准头部 for(int i=0; i