Module: CommonDataCaching

Defined in:
lib/common_data_caching.rb,
lib/common_data_caching/callbacks.rb,
lib/common_data_caching/class_methods.rb

Defined Under Namespace

Modules: Callbacks, ClassMethods

Class Method Summary collapse

Class Method Details

.update_cacheObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/common_data_caching.rb', line 12

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

.versionsObject



8
9
10
# File 'lib/common_data_caching.rb', line 8

def self.versions
  Rails.cache.read('common-data-caching-versions') || {}
end