* 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);
}
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:
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"))
/* XXX: unbusy, and kick other sessions into action */
sp->obj->busy = 0;
+ /* XXX: if not cachable, destroy */
+
return (1);
}