Skip to content

feat: add in-memory caching for faster wrapper data loading #9

Description

@SebastianBoehler

Context

Repeated data loading through the Tue API wrapper can be slow when the local API/sidecar repeatedly asks the same upstream university systems for data that has not changed yet. Add a small in-memory caching layer so repeated reads within one local process are faster while keeping credentialed university workflows local.

Source: Discord request from sebastian_boehler on 2026-05-21: "pls make the data loading faster and implement memory side caching in tue api wrapper".

Scope

  • Add or finalize a small typed in-memory cache utility under package/src/tue_api_wrapper/.
  • Support TTL-based entries, explicit cache keys, and cache clearing/invalidation.
  • Apply it first to high-impact read paths where the wrapper currently re-loads the same portal/dashboard data repeatedly, especially portal_service.py and the API route handlers that compose portal/dashboard responses.
  • Keep cache state process-local only. Do not persist credentials, session cookies, raw secret-bearing responses, or user data to disk.
  • Keep cache keys isolated by credential/session/user context and by request parameters so one user's data cannot be served to another user.
  • Do not cache failed upstream calls in a way that hides transient recovery.
  • Invalidate or bypass cached reads after mutating actions such as registration/edit/mail actions where stale data would be misleading.
  • Preserve existing route contracts and response shapes.

Acceptance criteria

  • Repeated identical read calls within the TTL avoid duplicate upstream loader/client calls.
  • Calls with different users/sessions or different request parameters use distinct cache entries.
  • Expired entries are reloaded.
  • Mutating endpoints either bypass cache or invalidate the affected cached data before returning.
  • Tests cover cache hit, miss, expiry, clear/invalidation, parameter isolation, and at least one integrated wrapper/route read path.
  • cd package && pytest passes.

Notes / risks

  • Prefer existing wrapper patterns and keep files focused, following the repository's 300-line modularity guideline.
  • Choose conservative TTL defaults so users see fresher university data rather than surprising stale results.
  • If adding observability, expose lightweight debug-friendly behavior without logging credentials or raw private payloads.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions