Class: AvroTurf::CachedSchemaRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/avro_turf/cached_schema_registry.rb

Overview

Caches registrations and lookups to the schema registry in memory.

Instance Method Summary collapse

Constructor Details

#initialize(upstream) ⇒ CachedSchemaRegistry

Returns a new instance of CachedSchemaRegistry.



6
7
8
9
10
# File 'lib/avro_turf/cached_schema_registry.rb', line 6

def initialize(upstream)
  @upstream = upstream
  @schemas_by_id = {}
  @ids_by_schema = {}
end

Instance Method Details

#fetch(id) ⇒ Object



19
20
21
# File 'lib/avro_turf/cached_schema_registry.rb', line 19

def fetch(id)
  @schemas_by_id[id] ||= @upstream.fetch(id)
end

#register(subject, schema) ⇒ Object



23
24
25
# File 'lib/avro_turf/cached_schema_registry.rb', line 23

def register(subject, schema)
  @ids_by_schema[subject + schema.to_s] ||= @upstream.register(subject, schema)
end