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.

Instance Method Summary collapse

Constructor Details

#initializeInMemoryCache

Returns a new instance of InMemoryCache.



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

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

Instance Method Details

#lookup_by_id(id) ⇒ Object



13
14
15
# File 'lib/avro_turf/in_memory_cache.rb', line 13

def lookup_by_id(id)
  @schemas_by_id[id]
end

#lookup_by_schema(subject, schema) ⇒ Object



21
22
23
24
# File 'lib/avro_turf/in_memory_cache.rb', line 21

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

#lookup_by_version(subject, version) ⇒ Object



43
44
45
46
# File 'lib/avro_turf/in_memory_cache.rb', line 43

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

#lookup_data_by_schema(subject, schema) ⇒ Object



26
27
28
29
# File 'lib/avro_turf/in_memory_cache.rb', line 26

def lookup_data_by_schema(subject, schema)
  key = [subject, schema]
  @data_by_schema[key]
end

#store_by_id(id, schema) ⇒ Object



17
18
19
# File 'lib/avro_turf/in_memory_cache.rb', line 17

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

#store_by_schema(subject, schema, id) ⇒ Object



31
32
33
34
# File 'lib/avro_turf/in_memory_cache.rb', line 31

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

#store_by_version(subject, version, schema) ⇒ Object



48
49
50
51
# File 'lib/avro_turf/in_memory_cache.rb', line 48

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

#store_data_by_schema(subject, schema, data) ⇒ Object



36
37
38
39
40
41
# File 'lib/avro_turf/in_memory_cache.rb', line 36

def store_data_by_schema(subject, schema, data)
  return unless data

  key = [subject, schema]
  @data_by_schema[key] = data
end