SubjectCache¶
-
class
kafkit.registry.sansio.SubjectCache(schema_cache)¶ 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, version)¶ Get the full set of schema and ID information for a subject version.
Parameters: Returns: - schema_info :
dict 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.
Raises: - ValueError
Raised if the schema does not exist in the cache.
See also
- schema_info :
-
get_id(subject, version)¶ Get the schema ID of a subject version.
Parameters: Returns: - schema_id :
int ID of the schema in a Schema Registry.
Raises: - ValueError
Raised if the schema does not exist in the cache.
See also
- schema_id :
-
get_schema(subject, version)¶ Get the schema of a subject version.
Parameters: Returns: - schema :
dict An Avro schema, preparsed by
fastavro.parse_schema.
Raises: - ValueError
Raised if the schema does not exist in the cache.
- schema :
-
insert(subject, version, schema_id=None, schema=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.
- schema_cache :