pgmemcache
pgmemcache
pgmemcache : memcached interface
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 9410 | pgmemcache | pgmemcache | 2.3.0 | SIM | MIT | C |
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
--s-d-r | No | Yes | No | Yes | yes | no |
| Relationships | |
|---|---|
| See Also | redis_fdw redis spat mongo_fdw kafka_fdw documentdb documentdb_core documentdb_distributed |
missing pg12-14 on el.aarch64
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | PGDG | 2.3.0 | 18 17 16 15 14 | pgmemcache | - |
| RPM | PGDG | 2.3.0 | 18 17 16 15 14 | pgmemcache_$v | - |
| DEB | PGDG | 2.3.0 | 18 17 16 15 14 | postgresql-$v-pgmemcache | - |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
el8.x86_64 | PGDG 2.3.0 | PGDG 2.3.0 | PGDG 2.3.0 | PGDG 2.3.0 | PGDG 2.3.0 |
el8.aarch64 | PGDG 2.3.0 | PGDG 2.3.0 | PGDG 2.3.0 | MISS | MISS |
el9.x86_64 | PGDG 2.3.0 | PGDG 2.3.0 | PGDG 2.3.0 | PGDG 2.3.0 | MISS |
el9.aarch64 | PGDG 2.3.0 | PGDG 2.3.0 | PGDG 2.3.0 | MISS | MISS |
el10.x86_64 | PGDG 2.3.0 | PGDG 2.3.0 | PGDG 2.3.0 | PGDG 2.3.0 | PGDG 2.3.0 |
el10.aarch64 | PGDG 2.3.0 | PGDG 2.3.0 | PGDG 2.3.0 | PGDG 2.3.0 | PGDG 2.3.0 |
d12.x86_64 | PGDG 2.3.0 | PGDG 2.3.0 | PGDG 2.3.0 | PGDG 2.3.0 | PGDG 2.3.0 |
d12.aarch64 | PGDG 2.3.0 | PGDG 2.3.0 | PGDG 2.3.0 | PGDG 2.3.0 | PGDG 2.3.0 |
d13.x86_64 | PGDG 2.3.0 | PGDG 2.3.0 | PGDG 2.3.0 | PGDG 2.3.0 | PGDG 2.3.0 |
d13.aarch64 | PGDG 2.3.0 | PGDG 2.3.0 | PGDG 2.3.0 | PGDG 2.3.0 | PGDG 2.3.0 |
u22.x86_64 | PGDG 2.3.0 | PGDG 2.3.0 | PGDG 2.3.0 | PGDG 2.3.0 | PGDG 2.3.0 |
u22.aarch64 | PGDG 2.3.0 | PGDG 2.3.0 | PGDG 2.3.0 | PGDG 2.3.0 | PGDG 2.3.0 |
u24.x86_64 | PGDG 2.3.0 | PGDG 2.3.0 | PGDG 2.3.0 | PGDG 2.3.0 | PGDG 2.3.0 |
u24.aarch64 | PGDG 2.3.0 | PGDG 2.3.0 | PGDG 2.3.0 | PGDG 2.3.0 | PGDG 2.3.0 |
Source
Install
Make sure PGDG repo available:
pig repo add pgdg -u # add pgdg repo and update cacheInstall this extension with pig:
pig install pgmemcache; # install via package name, for the active PG version
pig install pgmemcache -v 18; # install for PG 18
pig install pgmemcache -v 17; # install for PG 17
pig install pgmemcache -v 16; # install for PG 16
pig install pgmemcache -v 15; # install for PG 15
pig install pgmemcache -v 14; # install for PG 14Create this extension with:
CREATE EXTENSION pgmemcache;Usage
Provides PostgreSQL user-defined functions for interacting with memcached servers.
Enabling
CREATE EXTENSION pgmemcache;Configure default servers in postgresql.conf:
shared_preload_libraries = 'pgmemcache'
pgmemcache.default_servers = 'localhost:11211'
pgmemcache.default_behavior = 'DEAD_TIMEOUT:2'Server Management
SELECT memcache_server_add('localhost:11211');
SELECT memcache_server_add('cache-host'); -- uses default port 11211Setting and Getting Values
-- Set a key (overwrites if exists)
SELECT memcache_set('user:1:name', 'John Doe');
SELECT memcache_set('session:abc', 'data', now() + interval '1 hour');
-- Add a key (fails if exists)
SELECT memcache_add('user:2:name', 'Jane Doe');
SELECT memcache_add('temp_key', 'value', interval '5 minutes');
-- Replace (fails if key doesn't exist)
SELECT memcache_replace('user:1:name', 'John Smith');
-- Get a value
SELECT memcache_get('user:1:name'); -- returns text or NULL
-- Get multiple values
SELECT key, value FROM memcache_get_multi('{key1,key2,key3}'::text[]);Atomic Counters
SELECT memcache_incr('counter'); -- increment by 1
SELECT memcache_incr('counter', 5); -- increment by 5
SELECT memcache_decr('counter'); -- decrement by 1
SELECT memcache_decr('counter', 3); -- decrement by 3Deleting and Flushing
SELECT memcache_delete('user:1:name');
SELECT memcache_flush_all(); -- flush all serversStatistics
SELECT memcache_stats(); -- returns stats from all serversTrigger Example
Invalidate cache on table updates:
CREATE OR REPLACE FUNCTION auth_passwd_upd()
RETURNS TRIGGER LANGUAGE plpgsql AS $$
BEGIN
IF OLD.passwd <> NEW.passwd THEN
PERFORM memcache_delete('user_id_' || NEW.user_id || '_password');
END IF;
RETURN NEW;
END;
$$;
CREATE TRIGGER auth_passwd_upd_trg AFTER UPDATE ON passwd
FOR EACH ROW EXECUTE PROCEDURE auth_passwd_upd();Last updated on