Module: CommonDataCaching
- Defined in:
- lib/common_data_caching.rb,
lib/common_data_caching/version.rb,
lib/common_data_caching/callbacks.rb,
lib/common_data_caching/class_methods.rb
Defined Under Namespace
Modules: Callbacks, ClassMethods
Constant Summary
collapse
- VERSION =
'1.4.0'.freeze
Class Method Summary
collapse
Class Method Details
.all_collections ⇒ Object
16
17
18
19
20
21
22
23
|
# File 'lib/common_data_caching.rb', line 16
def self.all_collections
versions.map do |entity, _version|
{
entity:,
objects: entity.constantize.common_data_cache_collection
}
end
end
|
.collection(key) ⇒ Object
12
13
14
|
# File 'lib/common_data_caching.rb', line 12
def self.collection(key)
Rails.cache.fetch("common-data-caching_#{key}") || []
end
|
.update_cache ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/common_data_caching.rb', line 25
def self.update_cache
Rails.application.eager_load!
models = ActiveRecord::Base.descendants
Rails.cache.delete('common-data-caching-versions')
models.each do |model|
next unless model.common_data_caching?
model.update_common_data_cache
model.update_common_data_cache_versions
end
end
|
.versions ⇒ Object
8
9
10
|
# File 'lib/common_data_caching.rb', line 8
def self.versions
Rails.cache.read('common-data-caching-versions') || {}
end
|