Module: Stale::Dependencies
- Included in:
- Interface
- Defined in:
- lib/stale/dependencies.rb
Instance Method Summary collapse
- #add_dependency_to_list(dependency_key, key_string) ⇒ Object
- #dependency_key_for_collection(model_key) ⇒ Object
- #dependency_key_for_instance(model_key) ⇒ Object
- #expire_dependencies(model_key) ⇒ Object
- #expire_dependencies_from_list(dependency_key) ⇒ Object
- #register_dependencies(key_array) ⇒ Object
- #register_dependency(model_key, key_string) ⇒ Object
Instance Method Details
#add_dependency_to_list(dependency_key, key_string) ⇒ Object
29 30 31 32 33 |
# File 'lib/stale/dependencies.rb', line 29 def add_dependency_to_list(dependency_key, key_string) Stale.cache.modify(dependency_key) do |dependency_list| (Array(dependency_list) << key_string).uniq end end |
#dependency_key_for_collection(model_key) ⇒ Object
25 26 27 |
# File 'lib/stale/dependencies.rb', line 25 def dependency_key_for_collection(model_key) collection_from_key(model_key) + Stale.configuration[:dependency_key_suffix] end |
#dependency_key_for_instance(model_key) ⇒ Object
21 22 23 |
# File 'lib/stale/dependencies.rb', line 21 def dependency_key_for_instance(model_key) model_key + Stale.configuration[:dependency_key_suffix] end |
#expire_dependencies(model_key) ⇒ Object
12 13 14 15 |
# File 'lib/stale/dependencies.rb', line 12 def expire_dependencies(model_key) expire_dependencies_from_list(dependency_key_for_instance(model_key)) expire_dependencies_from_list(dependency_key_for_collection(model_key)) end |
#expire_dependencies_from_list(dependency_key) ⇒ Object
35 36 37 |
# File 'lib/stale/dependencies.rb', line 35 def expire_dependencies_from_list(dependency_key) Stale.cache.delete(*Array(Stale.cache.get(dependency_key))) end |
#register_dependencies(key_array) ⇒ Object
3 4 5 6 7 8 9 10 |
# File 'lib/stale/dependencies.rb', line 3 def register_dependencies(key_array) model_keys = models_from_key(key_array) key_string = key_as_string(key_array) model_keys.each do |model_key| register_dependency(model_key, key_string) end end |
#register_dependency(model_key, key_string) ⇒ Object
17 18 19 |
# File 'lib/stale/dependencies.rb', line 17 def register_dependency(model_key, key_string) add_dependency_to_list(dependency_key_for_instance(model_key), key_string) end |