Skip to content

Refactor endpoint caching to be explicit and typed#700

Merged
fderuiter merged 2 commits intomainfrom
refactor/explicit-endpoint-caching-5961568543587308941
Feb 24, 2026
Merged

Refactor endpoint caching to be explicit and typed#700
fderuiter merged 2 commits intomainfrom
refactor/explicit-endpoint-caching-5961568543587308941

Conversation

@fderuiter
Copy link
Owner

Refactored the caching mechanism in the endpoint classes to address "Primitive Obsession" and "Implicit vs Explicit" architectural smells.

Key changes:

  • Removed _cache_name property from EndpointABC and GenericEndpoint.
  • Added _enable_cache boolean flag to EndpointABC (default False).
  • Added _cache attribute to GenericEndpoint, strictly typed as Optional[Union[List[T], Dict[str, List[T]]]].
  • Updated GenericEndpoint.__init__ to initialize _cache explicitly based on _enable_cache and requires_study_key.
  • Refactored CacheMixin to use self._cache directly instead of dynamic attribute access.
  • Updated FormsEndpoint, StudiesEndpoint, VariablesEndpoint, and IntervalsEndpoint to set _enable_cache = True instead of defining _cache_name.
  • Updated EndpointProtocol to reflect these changes.

Verification:

  • Created a temporary verification script to assert correct cache initialization.
  • Ran existing unit tests for endpoints (test_studies_endpoint.py, test_forms_endpoint.py, etc.) which explicitly test caching behavior.
  • Ran the full unit test suite to ensure no regressions.
  • Verified strict typing and sync/async parity.

PR created automatically by Jules for task 5961568543587308941 started by @fderuiter

Replaced implicit `_cache_name` string property and dynamic `getattr`/`setattr` with explicit `_enable_cache` boolean and typed `_cache` attribute.
Updated `GenericEndpoint`, `CacheMixin`, `EndpointABC`, `EndpointProtocol` and all cached endpoints (`FormsEndpoint`, `StudiesEndpoint`, `VariablesEndpoint`, `IntervalsEndpoint`).
This improves type safety, reduces cognitive load, and eliminates "magic" string dependencies.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
@google-labs-jules
Copy link
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Removed `typing.Optional` from `imednet/core/endpoint/abc.py` and `imednet/core/endpoint/protocols.py` as it became redundant after replacing `_cache_name: Optional[str]` with `_enable_cache: bool`.
Fixes CI linting failures (F401).

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
@fderuiter fderuiter marked this pull request as ready for review February 24, 2026 14:39
@fderuiter fderuiter merged commit 916f080 into main Feb 24, 2026
13 checks passed
@fderuiter fderuiter deleted the refactor/explicit-endpoint-caching-5961568543587308941 branch February 24, 2026 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant