镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Limit the lifetime and size of the KGClient caches #168

Open

Description

@apdavison

Since #167, all of fairgraph's caching is done by the KGClient:

  • KGClient.cache, the JSON-LD documents of instances;
  • the existence cache, the ids found by, or created after, existence queries;
  • _query_cache, stored query definitions.

Each of these lasts as long as the client, and grows without limit (point 10 in #80).

That's fine for a client that only lives for one script run or one web request. But some clients live much longer: for example, service-account clients in web services, which are typically created once and kept for the life of the process, or long notebook sessions. For these:

  • The caches grow without limit.
  • Entries can be stale. A cached document is never refreshed unless the instance is changed through the same client, so changes made by others, or through another client in the same process, aren't seen.

Possible approaches, which could be combined:

  1. A maximum age (TTL) for cache entries, set in the KGClient constructor. This suits the existence cache especially well: it only needs to cover the delay before a new instance appears in query results, which is seconds or minutes.
  2. A maximum size, e.g. least-recently-used eviction.
  3. A public clear_cache() method, for applications that want to control this themselves, e.g. clearing a service client's caches at the start of each request.
  4. An option to turn caching off for a client.

Activity

  1. added this to the 1.0 milestone on Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestperformanceSomething should be faster

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions