silverp1/pb — pull request #36 by buhman (2014-12-06 07:41:55+00:00)
Title: cache invalidation

First, I had to write vcl (``/etc/varnish/default.vcl``) for varnish to process ``BAN`` requests over http:

```vcl
sub vcl_recv {
if (req.method == "BAN") {
if (!client.ip ~ purge) {
return(synth(405, "Not allowed."));
}

ban("req.http.host == " + req.http.host +
" && req.url ~ " + req.url);

return(synth(200, "Ban added."));
}
}
```

Added new ``VARNISH_BASE`` configuration parameter, which is already present on leviathan as a result of my testing:

```yaml
VARNISH_BASE: 'http://[::1]:8080/'
```

``ThreadPoolExecutor`` will handle the varnish request in parallel to request processing--the response may or may not complete before cache is actually invalidated, however invalidation is imminent regardless. Invalidation needs to occur on all of ``POST``, ``PUT``, and ``DELETE`` for hopefully obvious reasons.

Also needs (not currently in live db):

```sql
DELIMITER @@

DROP PROCEDURE IF EXISTS put_paste@@
CREATE PROCEDURE put_paste (
p_uuid BINARY(16),
p_content MEDIUMBLOB,
OUT p_id MEDIUMINT
)
BEGIN
START TRANSACTION;
SELECT id INTO p_id
FROM paste
WHERE uuid = p_uuid;
UPDATE paste
SET digest = UNHEX(SHA1(p_content)), content = p_content
WHERE uuid = p_uuid;
COMMIT;
END;
@@

DROP PROCEDURE IF EXISTS delete_paste@@
CREATE PROCEDURE delete_paste (
p_uuid BINARY(16),
OUT p_id MEDIUMINT
)
BEGIN
START TRANSACTION;
SELECT id INTO p_id
FROM paste
WHERE uuid = p_uuid;
DELETE
FROM paste
WHERE uuid = p_uuid;
COMMIT;
END;
@@
```