Commit 5dc7f0bc authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Use ttl=0 as a "invalid TTL" flag.

Mark objects with ttl=0 uncachable.

Add cacheable objects to the expiry heap

Start an expiry thread which polls the root element once per second




git-svn-id: http://www.varnish-cache.org/svn/trunk@231 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent eb7f8a7b
......@@ -138,6 +138,7 @@ void VBE_ClosedFd(void *ptr);
void VBE_RecycleFd(void *ptr);
/* cache_expiry.c */
void EXP_Insert(struct object *o);
void EXP_Init(void);
/* cache_fetch.c */
......
......@@ -4,7 +4,73 @@
* Expiry of cached objects and execution of prefetcher
*/
#include <pthread.h>
#include <unistd.h>
#include <assert.h>
#include <stdio.h>
#include "libvarnish.h"
#include "binary_heap.h"
#include "cache.h"
static pthread_t exp_thread;
static struct binheap *exp_heap;
static pthread_mutex_t expmtx;
/*--------------------------------------------------------------------*/
void
EXP_Insert(struct object *o)
{
AZ(pthread_mutex_lock(&expmtx));
binheap_insert(exp_heap, o);
AZ(pthread_mutex_unlock(&expmtx));
}
/*--------------------------------------------------------------------*/
static void *
exp_main(void *arg)
{
struct object *o;
time_t t;
while (1) {
time(&t);
AZ(pthread_mutex_lock(&expmtx));
o = binheap_root(exp_heap);
AZ(pthread_mutex_unlock(&expmtx));
if (o != NULL) {
printf("Root: %p %d (%d)\n",
(void*)o, o->ttl, o->ttl - t);
}
sleep(1);
}
return ("FOOBAR");
}
/*--------------------------------------------------------------------*/
static int
object_cmp(void *priv, void *a, void *b)
{
struct object *aa, *bb;
aa = a;
bb = b;
return (aa->ttl < bb->ttl);
}
/*--------------------------------------------------------------------*/
void
EXP_Init(void)
{
AZ(pthread_create(&exp_thread, NULL, exp_main, NULL));
AZ(pthread_mutex_init(&expmtx, NULL));
exp_heap = binheap_new(NULL, object_cmp, NULL);
assert(exp_heap != NULL);
}
......@@ -223,8 +223,6 @@ FetchSession(struct worker *w, struct sess *sp)
time(&t_resp);
http_Dissect(hp, fd, 2);
sp->obj->ttl = RFC2616_Ttl(hp, t_req, t_resp);
switch (http_GetStatus(hp)) {
case 200:
case 301:
......@@ -242,8 +240,16 @@ FetchSession(struct worker *w, struct sess *sp)
break;
}
sp->obj->ttl = RFC2616_Ttl(hp, t_req, t_resp);
if (sp->obj->ttl == 0) {
sp->obj->cacheable = 0;
}
VCL_fetch_method(sp);
if (sp->obj->cacheable)
EXP_Insert(sp->obj);
if (http_GetHdr(hp, "Content-Length", &b))
cls = fetch_straight(w, sp, fd, hp, b);
else if (http_HdrIs(hp, "Transfer-Encoding", "chunked"))
......@@ -264,5 +270,7 @@ FetchSession(struct worker *w, struct sess *sp)
/* XXX: unbusy, and kick other sessions into action */
sp->obj->busy = 0;
/* XXX: if not cachable, destroy */
return (1);
}
......@@ -82,7 +82,7 @@ RFC2616_Ttl(struct http *hp, time_t t_req, time_t t_resp)
ttl = t_resp + heritage.default_ttl;
printf("TTL: %d (%+d)\n", ttl, ttl - t_resp);
if (ttl < t_resp)
return (t_resp);
return (0);
return (ttl);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment