Skip to content

Instantly share code, notes, and snippets.

@nkallen
Created October 28, 2008 01:07
Show Gist options
  • Save nkallen/20257 to your computer and use it in GitHub Desktop.
Save nkallen/20257 to your computer and use it in GitHub Desktop.
backend default {
.host = "127.0.0.1";
.port = "3000";
}
C{
#include <dlfcn.h>
typedef int twitter_is_fresh_t(char *, char *);
static twitter_is_fresh_t *twitter_is_fresh_ptr;
void twitter_init() {
if (!twitter_is_fresh_ptr) {
void *library;
library = dlopen("freshyfresh.so", RTLD_NOW);
twitter_is_fresh_ptr = (twitter_is_fresh_t *)dlsym(library, "twitter_is_fresh");
}
}
int twitter_is_fresh(char *generation_key, char *etag) {
twitter_init();
return twitter_is_fresh_ptr(generation_key, etag);
}
}C
sub vcl_recv {
if (req.request != "GET" && req.request != "HEAD") {
pass;
}
if (req.http.Authorization) {
lookup;
}
}
sub vcl_hash {
set req.hash += req.url;
set req.hash += req.http.Authorization;
hash;
}
sub vcl_hit {
if (!obj.cacheable) {
pass;
}
call check_freshness;
deliver;
}
sub check_freshness {
C{
int fresh;
char *etag;
char *generation_key;
etag = VRT_GetHdr(sp, HDR_OBJ, "\005ETag:");
generation_key = VRT_GetHdr(sp, HDR_OBJ, "\021X-Generation-Key:");
if (!twitter_is_fresh(generation_key, etag)) {
VRT_l_obj_ttl(sp, (0 * 1));
VRT_done(sp, VCL_RET_PASS);
}
free(etag);
free(generation_key);
}C
}
sub vcl_fetch {
deliver;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment