Class: AvroTurf::CachedConfluentSchemaRegistry
- Inherits:
-
Object
- Object
- AvroTurf::CachedConfluentSchemaRegistry
- Defined in:
- lib/avro_turf/cached_confluent_schema_registry.rb
Overview
Caches registrations and lookups to the schema registry in memory.
Instance Method Summary collapse
- #check(subject, schema) ⇒ Object
- #fetch(id) ⇒ Object
-
#initialize(upstream, cache: nil) ⇒ CachedConfluentSchemaRegistry
constructor
Instantiate a new CachedConfluentSchemaRegistry instance with the given configuration.
- #register(subject, schema) ⇒ Object
- #subject_version(subject, version = 'latest') ⇒ Object
Constructor Details
#initialize(upstream, cache: nil) ⇒ CachedConfluentSchemaRegistry
Instantiate a new CachedConfluentSchemaRegistry instance with the given configuration. By default, uses a provided InMemoryCache to prevent repeated calls to the upstream registry.
upstream - The upstream schema registry object that fully responds to all methods in the
AvroTurf::ConfluentSchemaRegistry interface.
cache - Optional user provided Cache object that responds to all methods in the AvroTurf::InMemoryCache interface.
14 15 16 17 |
# File 'lib/avro_turf/cached_confluent_schema_registry.rb', line 14 def initialize(upstream, cache: nil) @upstream = upstream @cache = cache || AvroTurf::InMemoryCache.new end |
Instance Method Details
#check(subject, schema) ⇒ Object
27 28 29 |
# File 'lib/avro_turf/cached_confluent_schema_registry.rb', line 27 def check(subject, schema) @cache.lookup_data_by_schema(subject, schema) || @cache.store_data_by_schema(subject, schema, @upstream.check(subject, schema)) end |
#fetch(id) ⇒ Object
31 32 33 |
# File 'lib/avro_turf/cached_confluent_schema_registry.rb', line 31 def fetch(id) @cache.lookup_by_id(id) || @cache.store_by_id(id, @upstream.fetch(id)) end |
#register(subject, schema) ⇒ Object
35 36 37 |
# File 'lib/avro_turf/cached_confluent_schema_registry.rb', line 35 def register(subject, schema) @cache.lookup_by_schema(subject, schema) || @cache.store_by_schema(subject, schema, @upstream.register(subject, schema)) end |
#subject_version(subject, version = 'latest') ⇒ Object
39 40 41 42 43 44 |
# File 'lib/avro_turf/cached_confluent_schema_registry.rb', line 39 def subject_version(subject, version = 'latest') return @upstream.subject_version(subject, version) if version == 'latest' @cache.lookup_by_version(subject, version) || @cache.store_by_version(subject, version, @upstream.subject_version(subject, version)) end |