Module: Motor::Alerts::ScheduledAlertsCache

Defined in:
lib/motor/alerts/scheduled_alerts_cache.rb

Constant Summary collapse

CACHE_STORE =
ActiveSupport::Cache::MemoryStore.new(size: 5.megabytes)

Class Method Summary collapse

Class Method Details

.allObject



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/motor/alerts/scheduled_alerts_cache.rb', line 10

def all
  ActiveRecord::Base.logger.silence do
    cache_key = Motor::Alert.all.maximum(:updated_at)

    return [] if cache_key.nil?

    CACHE_STORE.fetch(cache_key) do
      clear

      Motor::Alert.all.active.enabled.to_a
    end
  end
end

.clearObject



24
25
26
# File 'lib/motor/alerts/scheduled_alerts_cache.rb', line 24

def clear
  CACHE_STORE.clear
end