SubjectCache¶
- class kafkit.registry.sansio.SubjectCache(schema_cache)¶
- Bases: - object- A 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:
- 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"), a- ValueErroris 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, version)¶
- 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, version)¶
- 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, version, schema_id=None, schema=None)¶
- Insert a subject version into the cache. - If the subject version being cached is already in the schema cache, then only one of - schema_idor- schemaneed to be passed to this method. However, if the schema isn’t cached, then both- schema_idand- schemaneed to be set. The- schema_idand- schemaare added to the underlying schema cache.- Parameters:
- Raises:
- TypeError – Raised if the - versionparameter is a string. String-based versions, like “latest,” cannot be cached.
- ValueError – Raised if the - schema_idor- schemaparameters are needed but aren’t set.
 
- Return type: