How long since an object was last accessed



I’m setting up some logging and one of the items it would be useful to know is how long it was since the object was last accessed.

Standard VCL has obj.lastuse. The documentation states for this:

obj.lastuse - The approximate time elapsed since the object was last requests, in seconds. This variable is also available in vcl_deliver.

Looking at the actual values given this is an absolute time of last use (eg, 1424204806.674).

In order to try getting a delta I’ve tried various options:

  • now - obj.lastuse (Errors with Expected CNUM got ‘obj.lastuse’)
  • now.sec - obj.lastuse (Errors with Expected variable, string or semicolon)
  • time.sub(now, obj.lastuse) (Errors with Expected a TIME variable)
  • time.sub(now.sec, obj.lastuse) (Errors with Expected a TIME variable, but now referencing now.sec)

I’m a bit stumped with this one. It looks like the new time functions expect a time object which is fine. There’s a way to convert a hex string to a time, but I can’t see a way to convert an inteteger to a time.

Any help would be much appreciated here.


Useful variables to log


The variable obj.lastuse works a bit differently in Fastly. Each edge node will have it’s own last accessed time. If the object is cached within the node, returned is the relative time in seconds since the object was last requested. If it is not cached, returned is now-lastuse. Except that lastuse is 0 if the cache does not remember seeing the object.

This variable is available in vcl_deliver and vcl_log.