Caching Behavior¶
This page explains how the SDK handles data caching.
Endpoint Caching¶
The SDK no longer maintains any stateful in-memory cache on endpoint instances.
Every call to list() performs a fresh API request,
ensuring that concurrent requests from different application contexts cannot
contaminate each other’s data.
If your application needs to reduce redundant API calls, implement caching at
the application layer using a library such as cachetools, a request-level
cache middleware (e.g. httpx-cache), or your framework’s own cache
primitives (e.g. Django’s cache framework or FastAPI dependency injection).
Schema Cache¶
SchemaCache (and
AsyncSchemaCache) stores Variable metadata
partitioned by (study_key, form_key) and (study_key, form_id) to validate
Record payloads locally. It can be populated explicitly via SchemaCache.refresh()
using FormsEndpoint and
VariablesEndpoint, or lazily through
SchemaValidator when validation runs.
What SchemaCache Validates vs. Skips¶
When BaseSchemaCache (SchemaCache and
AsyncSchemaCache) is hydrated from the REST /forms and /variables
endpoints, /forms provides Form identifiers and soft-deleted disabled
status (including zero-Variable Forms), while /variables provides structural
Variable types and retirement metadata without exposing required policies,
codelists, value bounds, or XML rules:
Enforced by
BaseSchemaCache(SchemaCache/AsyncSchemaCache): Form existence (including active zero-Variable Forms), soft-deletedForm.disabledrejection on new Record writes (rule_id="disabled_form"),formIdtoformKeyresolution, unknown Variable rejection, scalar and nested***MASKED***PHI sentinel rejection (rule_id="masked_phi"), and scalar Variable type checks (Number,Integer,Float,Date,Text—including historical type checks ondeletedanddisabledVariables stored in_retired_form_variableswithout requiring retired Variables to be populated). When unit tests or offline callers explicitly passrequiredpolicies viaSchemaCache.populate,BaseSchemaCachealso evaluatesYes(raisesValidationErrorwithrule_id="required") andAuto Query(logs a warning withrule_id="required_auto_query").Skipped by
BaseSchemaCachewhen hydrated from REST/formsand/variables: Study-defined Required Variable policies (omitted by REST/variables), Choice codelist membership, numeric (minValue/maxValue) and text length (minLength/maxLength) bounds, CDISC ODMRangeCheckConstraintchecks, and conditional XML business logic rules.
When you need Study-level required policy, constraint, and edit check
enforcement, load an offline DataDictionary
(CSV, CDISC ODM XML, or REDCap CSV) and pass schema=data_dictionary
to sdk.records.create, sdk.records.create_batch,
RecordUpdateWorkflow, or
RegisterSubjectsWorkflow. See
Data Dictionary Workflows and Rule Validation and Schema Validation Flow for
side-by-side details.
For lightweight type-check unit tests without a full Data Dictionary,
imednet.testing.fake_data includes helpers to generate Forms, Variables, and
Records that work with SchemaCache.refresh offline.