From: Daniel Gruno Date: Sun, 21 Apr 2013 07:12:27 +0000 (+0000) Subject: elaborate a bit about what ivm does, and add an example script X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e067bc09a59c4c294b02d7a8be78bb3e553bc3d8;p=thirdparty%2Fapache%2Fhttpd.git elaborate a bit about what ivm does, and add an example script git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1470271 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/docs/manual/mod/mod_lua.xml b/docs/manual/mod/mod_lua.xml index 32bb5219506..118815e67c6 100644 --- a/docs/manual/mod/mod_lua.xml +++ b/docs/manual/mod/mod_lua.xml @@ -891,10 +891,22 @@ r:dbacquire(dbType[, dbParams]) -- Acquires a connection to a database and retur r:ivm_set("key", value) -- Set an Inter-VM variable to hold a specific value. -- These values persist even though the VM is gone or not being used, -- and so should only be used if MaxConnectionsPerChild is > 0 - -- Values can be numbers, strings and booleans. + -- Values can be numbers, strings and booleans, and are stored on a + -- per process basis (so they won't do much good with a prefork mpm) r:ivm_get("key") -- Fetches a variable set by ivm_set. Returns the contents of the variable -- if it exists or nil if no such variable exists. + +-- An example getter/setter that saves a global variable outside the VM: +function handle(r) + -- First VM to call this will get no value, and will have to create it + local foo = r:ivm_get("cached_data") + if not foo then + foo = do_some_calcs() -- fake some return value + r:ivm_set("cached_data", foo) -- set it globally + end + r:puts("Cached data is: ", foo) +end