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.



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

def initialize
  @schemas_by_id = {}
  @ids_by_schema = {}
  @schema_by_subject_version = {}
  @data_by_schema = {}
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]
  @ids_by_schema[key]
end

#lookup_by_version(subject, version) ⇒ Object



41
42
43
44
# File 'lib/avro_turf/in_memory_cache.rb', line 41

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

#lookup_data_by_schema(subject, schema) ⇒ Object



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

def lookup_data_by_schema(subject, schema)
  key = [subject, schema]
  @data_by_schema[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



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

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

#store_by_version(subject, version, schema) ⇒ Object



46
47
48
49
# File 'lib/avro_turf/in_memory_cache.rb', line 46

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



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

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

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