Commit 46dc6d53 authored by Geoff Simmons's avatar Geoff Simmons

Add an example for the reader constructor, and docs for .get().

parent 54d08bfe
...@@ -213,18 +213,47 @@ Regardless of the value of ``log_checks``, errors encountered during ...@@ -213,18 +213,47 @@ Regardless of the value of ``log_checks``, errors encountered during
update checks are logged with the tag ``Error``, also with XID 0 (and update checks are logged with the tag ``Error``, also with XID 0 (and
hence visible in raw grouping). hence visible in raw grouping).
Examples::
sub vcl_init {
# A reader for the file at the absolute path, using default
# ttl=120s.
new foo = file.reader("/path/to/foo");
# A reader for the file on the default search path, with
# update checks every five minutes.
new synth_body = file.reader("synth_body.html", ttl=300s);
# A reader for the file on the given search path, with
# default TTL, and logging for update checks.
new bar = file.reader("bar", path="/var/run/d1:/var/run/d2",
log_checks=true);
# A reader for the file with no update checks.
new baz = file.reader("baz", ttl=0s);
}
.. _xreader.get(): .. _xreader.get():
STRING xreader.get() STRING xreader.get()
-------------------- --------------------
Retrieves the contents of file specified in the constructor. If the Return the contents of the file specified in the constructor, as
``ttl`` has elapsed, then ``.get()`` checks if the file has changed; currently cached. If the most recent update check encountered an
if so, the new contents of the file are read, cached and returned. If error, then VCL failure is invoked (see `ERRORS`_).
the ``ttl`` has not elapsed, or if the file is unchanged, then the
cached contents are returned.
XXX ... Example::
sub vcl_deliver {
set resp.http.Foo = foo.get();
}
Take care if you use ``.get()`` to set a header, as in the example,
that the file contents do *not* end in a newline. If so, then the
newline appears after the header contents, resulting in an empty line
after the header. Since an empty line separates the headers from the
body in an HTTP message, this is very likely to result in an invalid
message.
.. _xreader.synth(): .. _xreader.synth():
...@@ -241,7 +270,7 @@ XXX ... ...@@ -241,7 +270,7 @@ XXX ...
BOOL xreader.error() BOOL xreader.error()
-------------------- --------------------
Returns true if and only if an error condition was determined the last Return true if and only if an error condition was determined the last
time the file was checked. time the file was checked.
XXX ... XXX ...
...@@ -251,7 +280,7 @@ XXX ... ...@@ -251,7 +280,7 @@ XXX ...
STRING xreader.errmsg() STRING xreader.errmsg()
----------------------- -----------------------
Returns the error message for any error condition determined the last Return the error message for any error condition determined the last
time the file was checked, or a message indicating that there was no time the file was checked, or a message indicating that there was no
error. error.
...@@ -262,7 +291,7 @@ XXX ... ...@@ -262,7 +291,7 @@ XXX ...
BYTES xreader.size() BYTES xreader.size()
-------------------- --------------------
Returns the size of the file when it was most recently checked. Return the size of the file when it was most recently checked.
XXX ... XXX ...
...@@ -271,7 +300,7 @@ XXX ... ...@@ -271,7 +300,7 @@ XXX ...
TIME xreader.mtime() TIME xreader.mtime()
-------------------- --------------------
Returns the modification time of the file determined when it was mostly Return the modification time of the file determined when it was mostly
recently checked. recently checked.
XXX ... XXX ...
...@@ -281,7 +310,7 @@ XXX ... ...@@ -281,7 +310,7 @@ XXX ...
DURATION xreader.next_check() DURATION xreader.next_check()
----------------------------- -----------------------------
Returns the time remaining until the next check will be performed. Return the time remaining until the next check will be performed.
XXX ... XXX ...
......
...@@ -199,15 +199,44 @@ Regardless of the value of ``log_checks``, errors encountered during ...@@ -199,15 +199,44 @@ Regardless of the value of ``log_checks``, errors encountered during
update checks are logged with the tag ``Error``, also with XID 0 (and update checks are logged with the tag ``Error``, also with XID 0 (and
hence visible in raw grouping). hence visible in raw grouping).
Examples::
sub vcl_init {
# A reader for the file at the absolute path, using default
# ttl=120s.
new foo = file.reader("/path/to/foo");
# A reader for the file on the default search path, with
# update checks every five minutes.
new synth_body = file.reader("synth_body.html", ttl=300s);
# A reader for the file on the given search path, with
# default TTL, and logging for update checks.
new bar = file.reader("bar", path="/var/run/d1:/var/run/d2",
log_checks=true);
# A reader for the file with no update checks.
new baz = file.reader("baz", ttl=0s);
}
$Method STRING .get() $Method STRING .get()
Retrieves the contents of file specified in the constructor. If the Return the contents of the file specified in the constructor, as
``ttl`` has elapsed, then ``.get()`` checks if the file has changed; currently cached. If the most recent update check encountered an
if so, the new contents of the file are read, cached and returned. If error, then VCL failure is invoked (see `ERRORS`_).
the ``ttl`` has not elapsed, or if the file is unchanged, then the
cached contents are returned.
XXX ... Example::
sub vcl_deliver {
set resp.http.Foo = foo.get();
}
Take care if you use ``.get()`` to set a header, as in the example,
that the file contents do *not* end in a newline. If so, then the
newline appears after the header contents, resulting in an empty line
after the header. Since an empty line separates the headers from the
body in an HTTP message, this is very likely to result in an invalid
message.
$Method VOID .synth() $Method VOID .synth()
...@@ -218,14 +247,14 @@ XXX ... ...@@ -218,14 +247,14 @@ XXX ...
$Method BOOL .error() $Method BOOL .error()
Returns true if and only if an error condition was determined the last Return true if and only if an error condition was determined the last
time the file was checked. time the file was checked.
XXX ... XXX ...
$Method STRING .errmsg() $Method STRING .errmsg()
Returns the error message for any error condition determined the last Return the error message for any error condition determined the last
time the file was checked, or a message indicating that there was no time the file was checked, or a message indicating that there was no
error. error.
...@@ -233,20 +262,20 @@ XXX ... ...@@ -233,20 +262,20 @@ XXX ...
$Method BYTES .size() $Method BYTES .size()
Returns the size of the file when it was most recently checked. Return the size of the file when it was most recently checked.
XXX ... XXX ...
$Method TIME .mtime() $Method TIME .mtime()
Returns the modification time of the file determined when it was mostly Return the modification time of the file determined when it was mostly
recently checked. recently checked.
XXX ... XXX ...
$Method DURATION .next_check() $Method DURATION .next_check()
Returns the time remaining until the next check will be performed. Return the time remaining until the next check will be performed.
XXX ... XXX ...
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment