pod_cache_knowledge_store
A KnowledgeStore kept in the pod cache, shared by every process on the pod.
Classes
PodCacheKnowledgeStore
class PodCacheKnowledgeStore( cache: CacheProtocol, ehr_key: str, *, clock: Callable[[], float] = <built-in function monotonic>,):Findings about one EHR server, kept in the pod cache.
The EHR's findings are read when the store is built, and read again on the
first use after the copy held is SNAPSHOT_MAX_AGE old; every change is
written through. What other processes on the pod learn or clear about the
same EHR is therefore seen within SNAPSHOT_MAX_AGE. Until then this store
acts on what it loaded, so it can pay for what another process already
learned (such as timeouts on a search another process gave up on) for at
most that long.
A cache that cannot be read or written never fails an EHR request: the
failure is logged and the store carries on from memory. A read that fails
is tried again once per SNAPSHOT_MAX_AGE. A finding whose write the cache
refused is acted on in this process until the next successful read replaces
the findings held, and a finding whose removal the cache refused comes back
on that read.
Arguments
cache: The pod's background cache.ehr_key: The EHR's identity (bitfount.externals.ehr.identity.ehr_server_key).clock: Seconds on a clock that only moves forward, for the age of the findings held.
Methods
findings
def findings( self, kind: FindingKind | None = None,) ‑> list[Finding]:Every finding, or every finding of one kind.
Answered from the findings held, read again first if they are
SNAPSHOT_MAX_AGE old.
Arguments
kind: The kind to list, orNonefor all.
get
def get( self, kind: FindingKind, resource_type: str, subject: str = '',) ‑> Finding | None:The finding under a key, or None.
Answered from the findings held, read again first if they are
SNAPSHOT_MAX_AGE old.
Arguments
kind: What the finding is about.resource_type: The resource type it concerns.subject: Its subject (seeFinding.subject).
put
def put(self, finding: Finding) ‑> None:Store a finding, replacing any under the same key, and write it through.
Arguments
finding: The finding.
remove
def remove(self, kind: FindingKind, resource_type: str, subject: str = '') ‑> None:Forget the finding under a key, if there is one, and write that through.
A key this store holds no finding under is looked up in the cache, as another process may have recorded one since this store last loaded; it is deleted only if found. The removals made after every answered search therefore take no write lock when nothing is recorded.
Arguments
kind: What the finding is about.resource_type: The resource type it concerns.subject: Its subject (seeFinding.subject).
remove_if_unchanged
def remove_if_unchanged(self, finding: Finding) ‑> None:Forget a finding, unless another has been stored under its key since.
The row is deleted only while it holds the finding's due date, so a finding another process stored since this store last loaded is kept. This store's copy is dropped either way, and the next load reads what the cache holds.
Arguments
finding: The finding as it was read.