[Varnish] #412: make caching still possible in case of 'restart' from vcl_fetch and implement 'restart' from vcl_hit
Varnish
varnish-bugs at projects.linpro.no
Wed Dec 17 20:42:26 CET 2008
#412: make caching still possible in case of 'restart' from vcl_fetch and
implement 'restart' from vcl_hit
-------------------------+--------------------------------------------------
Reporter: hajile | Owner: phk
Type: enhancement | Status: new
Priority: normal | Milestone:
Component: varnishd | Version: trunk
Severity: normal | Keywords:
-------------------------+--------------------------------------------------
This is useful for caching redirects and following them internally (to
minimize network traffic)
for example with this config (internally following 303: See Other):
{{{
backend test {
.host = "127.0.0.1";
.port = "8080";
}
sub vcl_hit {
if (obj.http.X-Magic-Redirect == "1") {
set req.url = obj.http.Location;
restart;
}
}
sub vcl_fetch {
if (obj.status == 303) {
set obj.cacheable = true;
set obj.http.X-Magic-Redirect = "1";
set req.url = obj.http.Location;
restart;
}
}
}}}
{{{
--- varnish-2.0.2-orig/bin/varnishd/cache_center.c 2008-12-17
19:26:58.000000000 +0300
+++ varnish-2.0.2/bin/varnishd/cache_center.c 2008-12-17
19:36:43.000000000 +0300
@@ -413,8 +413,13 @@
switch (sp->handling) {
case VCL_RET_RESTART:
- sp->obj->ttl = 0;
- sp->obj->cacheable = 0;
+ if (sp->obj->ttl == 0) {
+ sp->obj->cacheable = 0;
+ }
+ if (sp->obj->objhead != NULL && sp->obj->cacheable == 1) {
+ VRY_Create(sp);
+ EXP_Insert(sp->obj);
+ }
HSH_Unbusy(sp);
HSH_Deref(sp->obj);
sp->obj = NULL;
@@ -529,6 +534,14 @@
VCL_hit_method(sp);
+ if (sp->handling == VCL_RET_RESTART) {
+ sp->step = STP_RECV;
+ HSH_Deref(sp->obj);
+ sp->obj = NULL;
+ sp->director = NULL;
+ return (0);
+ }
+
if (sp->handling == VCL_RET_DELIVER) {
/* Dispose of any body part of the request */
FetchReqBody(sp);
}}}
--
Ticket URL: <http://varnish.projects.linpro.no/ticket/412>
Varnish <http://varnish.projects.linpro.no/>
The Varnish HTTP Accelerator
More information about the varnish-bugs
mailing list