Class: ThreeScaleToolbox::RemoteCache
- Inherits:
-
BasicObject
- Defined in:
- lib/3scale_toolbox/remote_cache.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#create_backend_method(backend_id, metric_id, attributes) ⇒ Object
-
#create_backend_metric(backend_id, attributes) ⇒ Object
-
#create_method(service_id, metric_id, attributes) ⇒ Object
-
#create_metric(service_id, attributes) ⇒ Object
-
#delete_backend_method(backend_id, metric_id, method_id) ⇒ Object
-
#delete_backend_metric(backend_id, metric_id) ⇒ Object
-
#delete_method(service_id, parent_id, id) ⇒ Object
-
#delete_metric(service_id, metric_id) ⇒ Object
-
#initialize(subject) ⇒ RemoteCache
constructor
A new instance of RemoteCache.
-
#list_backend_methods(backend_id, metric_id) ⇒ Object
-
#list_backend_metrics(backend_id) ⇒ Object
-
#list_methods(service_id, metric_id) ⇒ Object
-
#list_metrics(service_id) ⇒ Object
-
#method_missing(name, *args) ⇒ Object
-
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
-
#update_backend_method(backend_id, metric_id, method_id, attributes) ⇒ Object
-
#update_backend_metric(backend_id, metric_id, attributes) ⇒ Object
-
#update_method(service_id, parent_id, id, attributes) ⇒ Object
-
#update_metric(service_id, metric_id, attributes) ⇒ Object
Constructor Details
#initialize(subject) ⇒ RemoteCache
Returns a new instance of RemoteCache.
6
7
8
9
10
11
12
13
14
15
16
|
# File 'lib/3scale_toolbox/remote_cache.rb', line 6
def initialize(subject)
@subject = subject
@metrics_cache = {}
@methods_cache = {}
@backend_metrics_cache = {}
@backend_methods_cache = {}
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
143
144
145
|
# File 'lib/3scale_toolbox/remote_cache.rb', line 143
def method_missing(name, *args)
subject.public_send(name, *args)
end
|
Instance Attribute Details
#backend_methods_cache ⇒ Object
Returns the value of attribute backend_methods_cache.
4
5
6
|
# File 'lib/3scale_toolbox/remote_cache.rb', line 4
def backend_methods_cache
@backend_methods_cache
end
|
#backend_metrics_cache ⇒ Object
Returns the value of attribute backend_metrics_cache.
4
5
6
|
# File 'lib/3scale_toolbox/remote_cache.rb', line 4
def backend_metrics_cache
@backend_metrics_cache
end
|
#methods_cache ⇒ Object
Returns the value of attribute methods_cache.
4
5
6
|
# File 'lib/3scale_toolbox/remote_cache.rb', line 4
def methods_cache
@methods_cache
end
|
#metrics_cache ⇒ Object
Returns the value of attribute metrics_cache.
4
5
6
|
# File 'lib/3scale_toolbox/remote_cache.rb', line 4
def metrics_cache
@metrics_cache
end
|
#subject ⇒ Object
Returns the value of attribute subject.
4
5
6
|
# File 'lib/3scale_toolbox/remote_cache.rb', line 4
def subject
@subject
end
|
Instance Method Details
#create_backend_method(backend_id, metric_id, attributes) ⇒ Object
114
115
116
117
118
119
120
121
|
# File 'lib/3scale_toolbox/remote_cache.rb', line 114
def create_backend_method(backend_id, metric_id, attributes)
subject.create_backend_method(backend_id, metric_id, attributes).tap do |method_attrs|
unless method_attrs.respond_to?(:has_key?) && !method_attrs['errors'].nil?
backend_metrics_cache.delete(backend_id)
backend_methods_cache.delete(method_cache_key(backend_id, metric_id))
end
end
end
|
#create_backend_metric(backend_id, attributes) ⇒ Object
96
97
98
99
100
|
# File 'lib/3scale_toolbox/remote_cache.rb', line 96
def create_backend_metric(backend_id, attributes)
subject.create_backend_metric(backend_id, attributes).tap do |metric_attrs|
backend_metrics_cache.delete(backend_id) unless metric_attrs.respond_to?(:has_key?) && !metric_attrs['errors'].nil?
end
end
|
#create_method(service_id, metric_id, attributes) ⇒ Object
61
62
63
64
65
66
|
# File 'lib/3scale_toolbox/remote_cache.rb', line 61
def create_method(service_id, metric_id, attributes)
subject.create_method(service_id, metric_id, attributes).tap do |method_attrs|
metrics_cache.delete(service_id) unless method_attrs.respond_to?(:has_key?) && !method_attrs['errors'].nil?
methods_cache.delete(method_cache_key(service_id, metric_id)) unless method_attrs.respond_to?(:has_key?) && !method_attrs['errors'].nil?
end
end
|
#create_metric(service_id, attributes) ⇒ Object
35
36
37
38
39
|
# File 'lib/3scale_toolbox/remote_cache.rb', line 35
def create_metric(service_id, attributes)
subject.create_metric(service_id, attributes).tap do |metric_attrs|
metrics_cache.delete(service_id) unless metric_attrs.respond_to?(:has_key?) && !metric_attrs['errors'].nil?
end
end
|
#delete_backend_method(backend_id, metric_id, method_id) ⇒ Object
123
124
125
126
127
128
|
# File 'lib/3scale_toolbox/remote_cache.rb', line 123
def delete_backend_method(backend_id, metric_id, method_id)
subject.delete_backend_method(backend_id, metric_id, method_id).tap do |_|
backend_metrics_cache.delete(backend_id)
backend_methods_cache.delete(method_cache_key(backend_id, metric_id))
end
end
|
#delete_backend_metric(backend_id, metric_id) ⇒ Object
108
109
110
111
112
|
# File 'lib/3scale_toolbox/remote_cache.rb', line 108
def delete_backend_metric(backend_id, metric_id)
subject.delete_backend_metric(backend_id, metric_id).tap do |_|
backend_metrics_cache.delete(backend_id)
end
end
|
#delete_method(service_id, parent_id, id) ⇒ Object
68
69
70
71
72
73
|
# File 'lib/3scale_toolbox/remote_cache.rb', line 68
def delete_method(service_id, parent_id, id)
subject.delete_method(service_id, parent_id, id).tap do |_|
metrics_cache.delete(service_id)
methods_cache.delete(method_cache_key(service_id, parent_id))
end
end
|
#delete_metric(service_id, metric_id) ⇒ Object
47
48
49
50
51
|
# File 'lib/3scale_toolbox/remote_cache.rb', line 47
def delete_metric(service_id, metric_id)
subject.delete_metric(service_id, metric_id).tap do |_|
metrics_cache.delete(service_id)
end
end
|
#list_backend_methods(backend_id, metric_id) ⇒ Object
87
88
89
90
91
92
93
94
|
# File 'lib/3scale_toolbox/remote_cache.rb', line 87
def list_backend_methods(backend_id, metric_id)
key = method_cache_key(backend_id, metric_id)
return backend_methods_cache[key] if backend_methods_cache.has_key? key
subject.list_backend_methods(backend_id, metric_id).tap do |methods|
backend_methods_cache[key] = methods unless methods.respond_to?(:has_key?) && !methods['errors'].nil?
end
end
|
#list_backend_metrics(backend_id) ⇒ Object
79
80
81
82
83
84
85
|
# File 'lib/3scale_toolbox/remote_cache.rb', line 79
def list_backend_metrics(backend_id)
return backend_metrics_cache[backend_id] if backend_metrics_cache.has_key? backend_id
subject.list_backend_metrics(backend_id).tap do |metrics|
backend_metrics_cache[backend_id] = metrics unless metrics.respond_to?(:has_key?) && !metrics['errors'].nil?
end
end
|
#list_methods(service_id, metric_id) ⇒ Object
26
27
28
29
30
31
32
33
|
# File 'lib/3scale_toolbox/remote_cache.rb', line 26
def list_methods(service_id, metric_id)
key = method_cache_key(service_id, metric_id)
return methods_cache[key] if methods_cache.has_key? key
subject.list_methods(service_id, metric_id).tap do |methods|
methods_cache[key] = methods unless methods.respond_to?(:has_key?) && !methods['errors'].nil?
end
end
|
#list_metrics(service_id) ⇒ Object
18
19
20
21
22
23
24
|
# File 'lib/3scale_toolbox/remote_cache.rb', line 18
def list_metrics(service_id)
return metrics_cache[service_id] if metrics_cache.has_key? service_id
subject.list_metrics(service_id).tap do |metrics|
metrics_cache[service_id] = metrics unless metrics.respond_to?(:has_key?) && !metrics['errors'].nil?
end
end
|
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
147
148
149
|
# File 'lib/3scale_toolbox/remote_cache.rb', line 147
def respond_to_missing?(method_name, include_private = false)
super
end
|
#update_backend_method(backend_id, metric_id, method_id, attributes) ⇒ Object
130
131
132
133
134
135
136
137
|
# File 'lib/3scale_toolbox/remote_cache.rb', line 130
def update_backend_method(backend_id, metric_id, method_id, attributes)
subject.update_backend_method(backend_id, metric_id, method_id, attributes).tap do |method_attrs|
unless method_attrs.respond_to?(:has_key?) && !method_attrs['errors'].nil?
backend_metrics_cache.delete(backend_id)
backend_methods_cache.delete(method_cache_key(backend_id, metric_id))
end
end
end
|
#update_backend_metric(backend_id, metric_id, attributes) ⇒ Object
102
103
104
105
106
|
# File 'lib/3scale_toolbox/remote_cache.rb', line 102
def update_backend_metric(backend_id, metric_id, attributes)
subject.update_backend_metric(backend_id, metric_id, attributes).tap do |metric_attrs|
backend_metrics_cache.delete(backend_id) unless metric_attrs.respond_to?(:has_key?) && !metric_attrs['errors'].nil?
end
end
|
#update_method(service_id, parent_id, id, attributes) ⇒ Object
53
54
55
56
57
58
|
# File 'lib/3scale_toolbox/remote_cache.rb', line 53
def update_method(service_id, parent_id, id, attributes)
subject.update_method(service_id, parent_id, id, attributes).tap do |method_attrs|
metrics_cache.delete(service_id) unless method_attrs.respond_to?(:has_key?) && !method_attrs['errors'].nil?
methods_cache.delete(method_cache_key(service_id, parent_id)) unless method_attrs.respond_to?(:has_key?) && !method_attrs['errors'].nil?
end
end
|
#update_metric(service_id, metric_id, attributes) ⇒ Object
41
42
43
44
45
|
# File 'lib/3scale_toolbox/remote_cache.rb', line 41
def update_metric(service_id, metric_id, attributes)
subject.update_metric(service_id, metric_id, attributes).tap do |metric_attrs|
metrics_cache.delete(service_id) unless metric_attrs.respond_to?(:has_key?) && !metric_attrs['errors'].nil?
end
end
|