SubjectCache¶
-
class
kafkit.registry.sansio.SubjectCache(schema_cache: kafkit.registry.sansio.SchemaCache)¶ Bases:
objectA cache of subjects in a schema registry that maps subject and version tuples to an actual schema.
- Parameters
schema_cache (
SchemaCache) – A schema cache instance.
Notes
The SubjectCache provides a subject-aware layer over the
SchemaCache. While schemas and their IDs are unique in a schema registry, multiple subject-version combinations can point to the same schema-ID combination.When you insert a schema into the SubjectCache, you are also inserting the schema and schema ID into the member
SchemaCache.Methods Summary
get(subject, version)Get the full set of schema and ID information for a subject version.
get_id(subject, version)Get the schema ID of a subject version.
get_schema(subject, version)Get the schema of a subject version.
insert(subject, version[, schema_id, schema])Insert a subject version into the cache.
Methods Documentation
-
get(subject: str, version: Union[int, str]) → Dict[str, Any]¶ Get the full set of schema and ID information for a subject version.
- Parameters
subject (
str) – The name of the subject.version (
int) – The version number of the schema in the subject. If version is given as a string ("latest"), aValueErroris raised.
- Returns
schema_info – A dictionary with the full set of information about the cached schema. The keys are:
"subject"The name of the subject.
"version"The version number of the schema in the subject.
"id"ID of the schema in a Schema Registry.
"schema"The Avro schema, preparsed by
fastavro.parse_schema.
- Return type
- Raises
ValueError – Raised if the schema does not exist in the cache.
See also
-
get_id(subject: str, version: int) → int¶ Get the schema ID of a subject version.
- Parameters
- Returns
schema_id – ID of the schema in a Schema Registry.
- Return type
- Raises
ValueError – Raised if the schema does not exist in the cache.
See also
-
get_schema(subject: str, version: int) → Dict[str, Any]¶ Get the schema of a subject version.
- Parameters
- Returns
schema – An Avro schema, preparsed by
fastavro.parse_schema.- Return type
- Raises
ValueError – Raised if the schema does not exist in the cache.
-
insert(subject: str, version: int, schema_id: Optional[int] = None, schema: Optional[Mapping[str, Any]] = None) → None¶ Insert a subject version into the cache.
- Parameters
- Raises
TypeError – Raised if the
versionparameter is a string. String-based versions, like “latest,” cannot be cached.ValueError – Raised if the
schema_idorschemaparameters are needed but aren’t set. See Notes.
Notes
If the subject version being cached is already in the schema cache, then only one of
schema_idorschemaneed to be passed to this method. However, if the schema isn’t cached, then bothschema_idandschemaneed to be set. Theschema_idandschemaare added to the underlying schema cache.