In our varnish config we have a vcl_fetch function defined as follows:
if (beresp.ttl > 0s) {
/* Remove Expires from backend, it's not long enough */
unset beresp.http.expires;
/* Set the clients TTL on this object */
set beresp.http.cache-control = "max-age=900";
/* Set how long Varnish will keep it */
set beresp.ttl = 1h;
/* marker for vcl_deliver to reset Age: */
set beresp.http.magicmarker = "1";
}
Then in vcl_deliver:
if (resp.http.magicmarker) {
/* Remove the magic marker */
unset resp.http.magicmarker;
/* By definition we have a fresh object */
set resp.http.age = "0";
}
The issue is that if I setup a script (either a shell script or a php script) to hit the same URL, I first see a MISS, followed by a HIT (all good so far).
What I am expecting to sit is repeated HITS until the 1 hour mark has passed, one MISS at the 1 hour mark, followed by an hour of HITs again. In other words because I'm hitting the same URL repeatedly it should cycle between HIT and MISS every 1 HOUR.
Instead what I see is something like this:
6/20/2013 6:30:05 - STRING HIT NOT FOUND
6/20/2013 10:32:11 - STRING HIT NOT FOUND
6/21/2013 12:33:06 - STRING HIT NOT FOUND
6/21/2013 2:34:06 - STRING HIT NOT FOUND
It's now 5:57AM (almost 4 hours since the HIT not found).
The cache misses above do all appear around the half hour mark but they're 4 hours, 2 hours and 2 hours apart and the TTL is set to 1 hour.
So I don't understand why the object is being kept longer than 1 hour and why its evicted at seemingly random intervals. How can I better determine whats going on?
By the way I am using varnish 3 if that helps.
So the varnish server in question was caching a Drupal 7 site. In the Drupal 7 site we had the Drupal Varnish module configured and enabled.
As best as I can tell that was periodically clearing the cache. I was able to determine that using the following command and seeing BANs that I hadn't issued: