From 9345142866554eacf8946890bb4c0911e76140d8 Mon Sep 17 00:00:00 2001 From: brettlangdon Date: Tue, 23 Jul 2013 09:02:37 -0400 Subject: [PATCH] allow record expiration to be disabled --- src/main.c | 2 +- src/proxy.c | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main.c b/src/main.c index be685a2..db8704b 100644 --- a/src/main.c +++ b/src/main.c @@ -36,7 +36,7 @@ void usage(){ "\t-w, --workers\t- how many background workers to spawn [default: 10]\r\n" "\t-u, --url\t- which url to proxy requests to [default: http://127.0.0.1:8000]\r\n" "\t-c, --cache\t- kyoto cabinet cache to use [default: \"*\"]\r\n" - "\t-e, --expire\t- the expiration time in seconds from when a record is cached [default:3600]\r\n" + "\t-e, --expire\t- the expiration time in seconds from when a record is cached, 0 to disable [default:3600]\r\n" "\t-h, --help\t- display this message\r\n"; printf("%s", usage_str); } diff --git a/src/proxy.c b/src/proxy.c index c8b0cff..e8362fe 100644 --- a/src/proxy.c +++ b/src/proxy.c @@ -39,8 +39,11 @@ void* call_proxy(void* arg){ curl_easy_setopt(curl, CURLOPT_WRITEDATA, result); res = curl_easy_perform(curl); char value[1024]; - int now = (int)time(NULL); - sprintf(value, "%10d:%s", now + record_expire_time, result->data); + int exp = 0; + if(record_expire_time > 0){ + exp = (int)time(NULL) + record_expire_time; + } + sprintf(value, "%10d:%s", exp, result->data); kcdbset(db, next, strlen(next), value, strlen(value)); if(url != NULL){