Class: AvroTurf::InMemoryCache

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

Overview

A cache for the CachedConfluentSchemaRegistry. Simply stores the schemas and ids in in-memory hashes.

Direct Known Subclasses

DiskCache

Instance Method Summary collapse

Constructor Details

#initializeInMemoryCache

Returns a new instance of InMemoryCache.



5
6
7
8
9
# File 'lib/avro_turf/in_memory_cache.rb', line 5

def initialize
  @schemas_by_id = {}
  @ids_by_schema = {}
  @schema_by_subject_version = {}
end

Instance Method Details

#lookup_by_id(id) ⇒ Object



11
12
13
# File 'lib/avro_turf/in_memory_cache.rb', line 11

def lookup_by_id(id)
  @schemas_by_id[id]
end

#lookup_by_schema(subject, schema) ⇒ Object



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

def lookup_by_schema(subject, schema)
  key = [subject, schema.to_s]
  @ids_by_schema[key]
end

#lookup_by_version(subject, version) ⇒ Object



29
30
31
32
# File 'lib/avro_turf/in_memory_cache.rb', line 29

def lookup_by_version(subject, version)
  key = "#{subject}#{version}"
  @schema_by_subject_version[key]
end

#store_by_id(id, schema) ⇒ Object



15
16
17
# File 'lib/avro_turf/in_memory_cache.rb', line 15

def store_by_id(id, schema)
  @schemas_by_id[id] = schema
end

#store_by_schema(subject, schema, id) ⇒ Object



24
25
26
27
# File 'lib/avro_turf/in_memory_cache.rb', line 24

def store_by_schema(subject, schema, id)
  key = [subject, schema.to_s]
  @ids_by_schema[key] = id
end

#store_by_version(subject, version, schema) ⇒ Object



34
35
36
37
# File 'lib/avro_turf/in_memory_cache.rb', line 34

def store_by_version(subject, version, schema)
  key = "#{subject}#{version}"
  @schema_by_subject_version[key] = schema
end