Module: StatsCacheable::ClassMethods

Defined in:
app/models/concerns/stats_cacheable.rb

Instance Method Summary collapse

Instance Method Details

#fetch_cached_statsObject



20
21
22
23
24
25
# File 'app/models/concerns/stats_cacheable.rb', line 20

def fetch_cached_stats
  # The scheduled Stats job is responsible for generating and caching this.
  stats = Discourse.redis.get(stats_cache_key)
  stats = refresh_stats if !stats
  JSON.parse(stats).with_indifferent_access
end

#fetch_statsObject



11
12
13
# File 'app/models/concerns/stats_cacheable.rb', line 11

def fetch_stats
  raise "Not implemented."
end

#recalculate_stats_intervalObject

Could be configurable, multisite need to support it.



16
17
18
# File 'app/models/concerns/stats_cacheable.rb', line 16

def recalculate_stats_interval
  30 # minutes
end

#refresh_statsObject



27
28
29
30
31
# File 'app/models/concerns/stats_cacheable.rb', line 27

def refresh_stats
  stats = fetch_stats.to_json
  set_cache(stats)
  stats
end

#stats_cache_keyObject



7
8
9
# File 'app/models/concerns/stats_cacheable.rb', line 7

def stats_cache_key
  raise "Stats cache key has not been set."
end