Class: Primer::Cache::Memory
Instance Attribute Summary
#routes, #throttle
Instance Method Summary
collapse
#compute, #primer_identifier, #regenerate
Methods included from Watcher
call_log, included, log, loggers, on_disable, on_enable, #primer_identifier, reset!, watching
Methods included from Enabler
#disable!, #enable!, #enabled?
Constructor Details
#initialize ⇒ Memory
Returns a new instance of Memory.
5
6
7
|
# File 'lib/primer/cache/memory.rb', line 5
def initialize
clear
end
|
Instance Method Details
#clear ⇒ Object
9
10
11
12
13
|
# File 'lib/primer/cache/memory.rb', line 9
def clear
@data_store = {}
@relations = {}
@dependencies = {}
end
|
#get(cache_key) ⇒ Object
21
22
23
24
|
# File 'lib/primer/cache/memory.rb', line 21
def get(cache_key)
validate_key(cache_key)
@data_store[cache_key]
end
|
#has_key?(cache_key) ⇒ Boolean
26
27
28
|
# File 'lib/primer/cache/memory.rb', line 26
def has_key?(cache_key)
@data_store.has_key?(cache_key)
end
|
#invalidate(cache_key) ⇒ Object
30
31
32
33
34
35
36
37
|
# File 'lib/primer/cache/memory.rb', line 30
def invalidate(cache_key)
@data_store.delete(cache_key)
return unless deps = @dependencies[cache_key]
deps.each do |attribute|
@relations[attribute].delete(cache_key)
end
@dependencies.delete(cache_key)
end
|
#keys_for_attribute(attribute) ⇒ Object
48
49
50
51
|
# File 'lib/primer/cache/memory.rb', line 48
def keys_for_attribute(attribute)
return [] unless keys = @relations[attribute]
keys.to_a
end
|
#put(cache_key, value) ⇒ Object
15
16
17
18
19
|
# File 'lib/primer/cache/memory.rb', line 15
def put(cache_key, value)
validate_key(cache_key)
@data_store[cache_key] = value
publish_change(cache_key)
end
|
#relate(cache_key, attributes) ⇒ Object
39
40
41
42
43
44
45
46
|
# File 'lib/primer/cache/memory.rb', line 39
def relate(cache_key, attributes)
deps = @dependencies[cache_key] ||= Set.new
attributes.each do |attribute|
deps.add(attribute)
list = @relations[attribute] ||= Set.new
list.add(cache_key)
end
end
|
#timeout(cache_key, &block) ⇒ Object
53
54
55
|
# File 'lib/primer/cache/memory.rb', line 53
def timeout(cache_key, &block)
add_timeout(cache_key, @throttle, &block)
end
|