mirror of
https://github.com/postgres/pgweb.git
synced 2025-07-25 16:02:27 +00:00

It's just another type of purge, so it's added as an extra option with 'K' as the key (as 'X' was already taken).
38 lines
1.4 KiB
PL/PgSQL
38 lines
1.4 KiB
PL/PgSQL
BEGIN;
|
|
|
|
--
|
|
-- Create a function to purge from varnish cache
|
|
-- By default this adds the object to a local queue,
|
|
-- but this function can be replaced with a void one
|
|
-- when running a development version.
|
|
--
|
|
|
|
CREATE SCHEMA IF NOT EXISTS varnishqueue;
|
|
CREATE TABLE IF NOT EXISTS varnishqueue.queue (id bigserial primary key, mode char NOT NULL, consumerid int NOT NULL, expr text NOT NULL, added timestamptz NOT NULL DEFAULT CURRENT_TIMESTAMP, completed timestamptz NULL);
|
|
CREATE TABLE IF NOT EXISTS varnishqueue.consumers (consumerid serial PRIMARY KEY, consumer text NOT NULL);
|
|
|
|
DROP FUNCTION IF EXISTS varnish_purge(url text);
|
|
CREATE OR REPLACE FUNCTION varnish_purge(url text)
|
|
RETURNS void
|
|
AS $$
|
|
INSERT INTO varnishqueue.queue (mode, consumerid, expr) SELECT 'P', consumerid, $1 FROM varnishqueue.consumers;
|
|
NOTIFY varnishqueue;
|
|
$$ LANGUAGE 'sql';
|
|
|
|
DROP FUNCTION IF EXISTS varnish_purge_expr(expr text);
|
|
CREATE OR REPLACE FUNCTION varnish_purge_expr(expr text)
|
|
RETURNS void
|
|
AS $$
|
|
INSERT INTO varnishqueue.queue (mode, consumerid, expr) SELECT 'X', consumerid, $1 FROM varnishqueue.consumers;
|
|
NOTIFY varnishqueue;
|
|
$$ LANGUAGE 'sql';
|
|
|
|
DROP FUNCTION IF EXISTS varnish_purge_xkey(key text);
|
|
CREATE OR REPLACE FUNCTION varnish_purge_xkey(key text)
|
|
RETURNS void
|
|
AS $$
|
|
INSERT INTO varnishqueue.queue (mode, consumerid, expr) SELECT 'K', consumerid, $1 FROM varnishqueue.consumers;
|
|
NOTIFY varnishqueue;
|
|
$$ LANGUAGE 'sql';
|
|
COMMIT;
|