Class: Ultracache::Configurations
- Inherits:
-
Object
- Object
- Ultracache::Configurations
- Defined in:
- lib/ultracache/configurations.rb
Overview
This class contains configurations for Ultracache. Proper configurations should be set before caching objects and attributes you need.
Put configurations for your Rails project into initializer:
# config/initializers/ultracache.rb
Ultracache.config do |config|
config.storage = Ultracache::Storage::Redis.new
config.serializer = Ultracache::Serializer::JsonSerializer.new
end
Configurable attributes include ‘storage` and `serializer` for now.
Class Method Summary collapse
- .add_relationships(klass) ⇒ Object
- .find_relationships(klass, options = {}) ⇒ Object
- .relationships_container ⇒ Object
-
.serializer ⇒ Object
Getter for serializer of Ultracache.
-
.serializer=(serializer) ⇒ Object
Setter for serializer of Ultracache.
-
.storage ⇒ Object
Getter for storage handler of Ultracache.
-
.storage=(storage) ⇒ Object
Setter for storage handler of Ultracache.
Class Method Details
.add_relationships(klass) ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/ultracache/configurations.rb', line 41 def add_relationships(klass) unless relationships_container[klass] rs = Relationships.new(klass) relationships_container[klass] = rs rs else nil end end |
.find_relationships(klass, options = {}) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/ultracache/configurations.rb', line 51 def find_relationships(klass, = {}) rs_set = [] relationships_container.each do |k, rs| if klass == k return rs if [:strict] rs_set << rs end end return nil if [:strict] relationships_container.each do |k, rs| if klass <= k rs_set << rs end end if rs_set.empty? nil else rs_set.inject(Relationships.new(klass)) do |base, rs| base.merge(rs) end end end |
.relationships_container ⇒ Object
37 38 39 |
# File 'lib/ultracache/configurations.rb', line 37 def relationships_container @relationships ||= Hash.new end |
.serializer ⇒ Object
Getter for serializer of Ultracache.
33 34 35 |
# File 'lib/ultracache/configurations.rb', line 33 def serializer @serializer end |
.serializer=(serializer) ⇒ Object
Setter for serializer of Ultracache. ‘Ultracache::Serializer::JsonSerializer` is set as default value.
28 29 30 |
# File 'lib/ultracache/configurations.rb', line 28 def serializer=(serializer) @serializer = serializer end |
.storage ⇒ Object
Getter for storage handler of Ultracache.
22 23 24 |
# File 'lib/ultracache/configurations.rb', line 22 def storage @storage end |
.storage=(storage) ⇒ Object
Setter for storage handler of Ultracache.
17 18 19 |
# File 'lib/ultracache/configurations.rb', line 17 def storage=(storage) @storage = storage end |