Persistence

Multiple persistence solutions have bindings in Vala and can be used by Valum.

One good general approach is to use a per-process connection pool since handlers are executing in asynchronous context, your application will greatly benefit from multiple connections.

Memcached

You can use libmemcached.vapi to access a Memcached cache storage, it is maintained in nemequ/vala-extra-vapis GitHub repository.

using Valum;
using VSGI;

var app       = new Router ();
var memcached = new Memcached.Context ();

app.get ("/<key>", (req, res) => {
    var key = req.params["key"];

    int32 flags;
    Memcached.ReturnCode error;
    var value = memcached.get ("hello", out flags, out error);

    return res.expand (value, null);
});

app.post ("/<key>", (req, res) => {
    var key    = req.params["key"];
    var buffer = new MemoryOutputStream.resizable ();

    // fill the buffer with the request body
    buffer.splice (req);

    int32 flags;
    Memcached.ReturnCode error;
    var value = memcached.get ("hello", out flags, out error);

    return res.expand (value, null);
});

Server.new ("http", handler: app).run ();