layers_clearCache control
pgRDF keeps two caches:
| Cache | Where it lives | What it holds |
|---|---|---|
| Shared term cache | Shared memory, one per server (needs shared_preload_libraries) | Recently used RDF terms and their dictionary ids, so loading doesn't look every term up in the dictionary table |
| Plan cache | Each connection | The SQL translation of SPARQL queries that connection has run |
Neither needs routine maintenance. Loading, updating, clearing and dropping graphs keep both caches correct. You don't clear anything after changing data.
After re-creating the extension
There is one case that needs action. If you drop and re-create the extension while the server keeps running (for example, resetting a test database), invalidate the shared term cache straight after CREATE EXTENSION:
DROP EXTENSION pgrdf CASCADE;
CREATE EXTENSION pgrdf;
SELECT pgrdf.shmem_reset();shmem_reset() returns nothing and affects the whole server. The cache refills as data is loaded. The cumulative counters in pgrdf.stats() keep their totals. A server restart also starts with an empty cache.
Warming the cache after a restart
After a restart the shared term cache is empty, so the first large load does more dictionary lookups. To fill the cache from the dictionary before the first load, turn on:
SET pgrdf.shmem_prewarm_on_init = on; -- default offSee Settings for every setting.
Diagnostic functions
pgrdf.surface() lists the stability class of each function. Two cache functions are internal: diagnostics, not part of any workflow, and subject to change.
SELECT name, class FROM pgrdf.surface()
WHERE name IN ('shmem_reset', 'shmem_cache_prewarm', 'plan_cache_clear')
ORDER BY name; name | class
---------------------+----------
plan_cache_clear | internal
shmem_cache_prewarm | internal
shmem_reset | stableplan_cache_clear()drops the calling connection's plan cache and returns how many plans it held. Closing the connection has the same effect.shmem_cache_prewarm(limit)loads up tolimitterms into the shared term cache; thepgrdf.shmem_prewarm_on_initsetting above is the supported way to warm it.
See also
- Counters and health: cache hit and miss counters.
- Plan cache.
- Shared-memory dictionary cache.