Class: Orchestrate::Application::SimpleCacheCollection

Inherits:
Object
  • Object
show all
Defined in:
lib/orchestrate_application/simple_cache_store.rb

Overview

Class SimpleCacheCollection

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ SimpleCacheCollection

Returns a new instance of SimpleCacheCollection.



37
38
39
40
# File 'lib/orchestrate_application/simple_cache_store.rb', line 37

def initialize(name)
  @name = name
  @primary_keys, @events, @graphs = {}, {}, {}
end

Instance Attribute Details

#eventsObject (readonly)

Returns the value of attribute events.



35
36
37
# File 'lib/orchestrate_application/simple_cache_store.rb', line 35

def events
  @events
end

#graphsObject (readonly)

Returns the value of attribute graphs.



35
36
37
# File 'lib/orchestrate_application/simple_cache_store.rb', line 35

def graphs
  @graphs
end

#nameObject (readonly)

Returns the value of attribute name.



35
36
37
# File 'lib/orchestrate_application/simple_cache_store.rb', line 35

def name
  @name
end

#primary_keysObject (readonly)

Returns the value of attribute primary_keys.



35
36
37
# File 'lib/orchestrate_application/simple_cache_store.rb', line 35

def primary_keys
  @primary_keys
end

Instance Method Details

#fetch(key) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/orchestrate_application/simple_cache_store.rb', line 46

def fetch(key)
  # puts "SCC-fetching: '#{key}', '#{primary_keys[key]}'"
  if primary_keys[key]
    # puts "SCC-fetching: '#{primary_keys[key].ref}'"
    SimpleCacheRefs.instance.document primary_keys[key].ref
  end
end

#fetch_events(key, etype) ⇒ Object



54
55
56
57
58
59
60
61
62
# File 'lib/orchestrate_application/simple_cache_store.rb', line 54

def fetch_events(key, etype)
  # puts "SCC-fetch_events: '#{key}', '#{etype}'"
  if primary_keys[key] and primary_keys[key].events[etype]
    primary_keys[key].events[etype].map { |ref|
      # puts "SCC-fetch_events: '#{ref}'"
      SimpleCacheRefs.instance.document ref
    }
  end
end

#fetch_graph(key, kind) ⇒ Object



64
65
66
67
68
69
70
71
72
# File 'lib/orchestrate_application/simple_cache_store.rb', line 64

def fetch_graph(key, kind)
  # puts "SCC-fetch_graph 1: '#{key}', '#{kind}'"
  if primary_keys[key] and primary_keys[key].graphs and primary_keys[key].graphs[kind]
    primary_keys[key].graphs[kind].map { |ref|
      # puts "SCC-fetch_graph: '#{ref}'"
      SimpleCacheRefs.instance.document ref
    }
  end
end

#flush!Object



42
43
44
# File 'lib/orchestrate_application/simple_cache_store.rb', line 42

def flush!
  @primary_keys, @events, @graphs = {}, {}, {}
end

#get_ref(key) ⇒ Object



74
75
76
# File 'lib/orchestrate_application/simple_cache_store.rb', line 74

def get_ref(key)
  primary_keys[key] and primary_keys[key].ref
end

#save(data) ⇒ Object



78
79
80
81
82
83
84
85
86
# File 'lib/orchestrate_application/simple_cache_store.rb', line 78

def save(data)
  key, ref = data.key, data.ref
  @primary_keys[key] = PrimaryKey.new(ref) if primary_keys[key].nil?
  if data.respond_to? :etype and data.etype
    @primary_keys[key].add_event(data.etype, ref)
  else
    @primary_keys[key].ref = ref
  end
end

#save_event(data) ⇒ Object



88
89
90
91
# File 'lib/orchestrate_application/simple_cache_store.rb', line 88

def save_event(data)
  @primary_keys[data.key] = PrimaryKey.new(0) if primary_keys[data.key].nil?
  @primary_keys[data.key].add_event data.etype
end

#save_graph(data) ⇒ Object



93
94
95
96
# File 'lib/orchestrate_application/simple_cache_store.rb', line 93

def save_graph(data)
  @primary_keys[data.from_key] = PrimaryKey.new(0) if primary_keys[data.from_key].nil?
  @primary_keys[data.from_key].add_graph data
end