Class: SavonHelper::CachingObject
Constant Summary
collapse
- @@cache_aspects =
Hash.new { |hash, key| hash[key] = Set.new() }
- @@cache =
Cache.new(nil, nil, 10000, 5*60)
MappingObject::BLACK_LIST
Instance Attribute Summary
#interface
Attributes included from DSL
#alias_accessor
all_type_mappings, defined_attributes, has_attribute_chain, #initialize, #to_json, #to_s, #to_savon, type_mappings
Methods included from DSL
#array_boolean_accessor, #array_datetime_accessor, #array_double_accessor, #array_enum_accessor, #array_float__accessor, #array_integer_accessor, #array_ip_address_accessor, #array_object_accessor, #array_string_accessor, #attr_boolean_accessor, #attr_datetime_accessor, #attr_double_accessor, #attr_enum_accessor, #attr_float_accessor, #attr_integer_accessor, #attr_ip_address_accessor, #attr_object_accessor, #attr_string_accessor, #hint_object_accessor
Class Method Details
.all_cache_aspects ⇒ Object
18
19
20
|
# File 'lib/savon_helper/caching_object.rb', line 18
def self.all_cache_aspects
self.superclass.all_cache_aspects + cache_aspects()
end
|
.cache_aspects ⇒ Object
14
15
16
|
# File 'lib/savon_helper/caching_object.rb', line 14
def self.cache_aspects
@@cache_aspects[self]
end
|
.cache_by_aspect(*symbols) ⇒ Object
22
23
24
|
# File 'lib/savon_helper/caching_object.rb', line 22
def self.cache_by_aspect(*symbols)
symbols.each { |each| cache_aspects.add(each) }
end
|
.cache_key(aspect, value) ⇒ Object
26
27
28
|
# File 'lib/savon_helper/caching_object.rb', line 26
def self.cache_key(aspect, value)
"#{self.name_without_namespace}-#{aspect}-#{value}"
end
|
.from_savon(data, interface) ⇒ MappingObject
Return an initialized instance with the values from the (type-converted) hash. Store the instance in cache
if cacheable.
56
57
58
59
60
|
# File 'lib/savon_helper/caching_object.rb', line 56
def self.from_savon(data, interface)
instance = super(data, interface)
instance.store_in_cache if instance.cachable?
instance
end
|
Instance Method Details
#cachable? ⇒ Boolean
34
35
36
|
# File 'lib/savon_helper/caching_object.rb', line 34
def cachable?
!all_cache_aspects.empty?
end
|
38
39
40
|
# File 'lib/savon_helper/caching_object.rb', line 38
def cache
@@cache
end
|
#cache_key(aspect) ⇒ Object
30
31
32
|
# File 'lib/savon_helper/caching_object.rb', line 30
def cache_key(aspect)
self.class.cache_key(aspect, self.send(aspect))
end
|
#store_in_cache ⇒ Object
42
43
44
|
# File 'lib/savon_helper/caching_object.rb', line 42
def store_in_cache
all_cache_aspects.each { |aspect| cache.store(self.cache_key(aspect), self) }
end
|