Class: Orchestrate::Application::SimpleCacheStore
- Inherits:
-
Object
- Object
- Orchestrate::Application::SimpleCacheStore
- Defined in:
- lib/orchestrate_application/simple_cache_store.rb
Overview
When enabled, the cache mechanism:
* is useful for development/testing, minimizing calls to the server.
* is updated upon each GET or PUT request.
* remains active for the lifespan of the application.
Constant Summary collapse
- @@instance =
SimpleCacheStore.new
Class Method Summary collapse
Instance Method Summary collapse
- #cache ⇒ Object
- #disable ⇒ Object
- #enable ⇒ Object
- #fetch(collection, key) ⇒ Object
- #flush!(collection = nil) ⇒ Object
- #get_cache_collection(name) ⇒ Object
- #get_cc(name) ⇒ Object
- #get_ref(collection_name, key) ⇒ Object
-
#initialize ⇒ SimpleCacheStore
constructor
A new instance of SimpleCacheStore.
- #is_enabled? ⇒ Boolean
- #save(document) ⇒ Object
- #simple_cache_init ⇒ Object
Constructor Details
#initialize ⇒ SimpleCacheStore
Returns a new instance of SimpleCacheStore.
130 131 132 133 134 135 |
# File 'lib/orchestrate_application/simple_cache_store.rb', line 130 def initialize @@is_enabled ||= false @@cache ||= simple_cache_init # puts "SC-init: cache -> '#{@@cache}', '#{!@@cache.nil?}'" @@refs ||= {} end |
Class Method Details
.disable ⇒ Object
156 157 158 159 |
# File 'lib/orchestrate_application/simple_cache_store.rb', line 156 def self.disable puts "SC-DISABLE" @@is_enabled = false end |
.enable ⇒ Object
150 151 152 153 154 |
# File 'lib/orchestrate_application/simple_cache_store.rb', line 150 def self.enable puts "SC-ENABLE" @@is_enabled = true # puts "SIMPLE-CACHE has been DISABLED for the current version." end |
.instance ⇒ Object
145 146 147 148 |
# File 'lib/orchestrate_application/simple_cache_store.rb', line 145 def self.instance @@cache ||= @@instance.simple_cache_init @@instance end |
Instance Method Details
#cache ⇒ Object
167 168 169 |
# File 'lib/orchestrate_application/simple_cache_store.rb', line 167 def cache @@cache end |
#disable ⇒ Object
210 211 212 |
# File 'lib/orchestrate_application/simple_cache_store.rb', line 210 def disable self.class.disable end |
#enable ⇒ Object
206 207 208 |
# File 'lib/orchestrate_application/simple_cache_store.rb', line 206 def enable self.class.enable end |
#fetch(collection, key) ⇒ Object
198 199 200 |
# File 'lib/orchestrate_application/simple_cache_store.rb', line 198 def fetch(collection, key) get_cc(collection).fetch(key) end |
#flush!(collection = nil) ⇒ Object
171 172 173 174 175 176 177 |
# File 'lib/orchestrate_application/simple_cache_store.rb', line 171 def flush!(collection=nil) if collection get_cc(collection).flush! else @@cache = simple_cache_init end end |
#get_cache_collection(name) ⇒ Object
179 180 181 |
# File 'lib/orchestrate_application/simple_cache_store.rb', line 179 def get_cache_collection(name) cache[name] end |
#get_cc(name) ⇒ Object
183 184 185 |
# File 'lib/orchestrate_application/simple_cache_store.rb', line 183 def get_cc(name) get_cache_collection name end |
#get_ref(collection_name, key) ⇒ Object
194 195 196 |
# File 'lib/orchestrate_application/simple_cache_store.rb', line 194 def get_ref(collection_name, key) get_cc(collection_name).get_ref key end |
#is_enabled? ⇒ Boolean
202 203 204 |
# File 'lib/orchestrate_application/simple_cache_store.rb', line 202 def is_enabled? @@is_enabled end |
#save(document) ⇒ Object
187 188 189 190 191 192 |
# File 'lib/orchestrate_application/simple_cache_store.rb', line 187 def save(document) m = document. get_cc(m.from_collection).save_graph(m) if m.respond_to? :kind and m.kind get_cc(m.collection).save m SimpleCacheRefs.instance.save m.ref, document end |
#simple_cache_init ⇒ Object
137 138 139 140 141 142 143 |
# File 'lib/orchestrate_application/simple_cache_store.rb', line 137 def simple_cache_init cache = Hash[Schema.instance.collection_names.map { |name| [name, SimpleCacheCollection.new(name)] }] # puts "SC-sc_init -> '#{cache}', is_enabled -> '#{@@is_enabled}'" cache == {} ? nil : cache end |