Module: StatsCacheable::ClassMethods
- Defined in:
- app/models/concerns/stats_cacheable.rb
Instance Method Summary collapse
- #fetch_cached_stats ⇒ Object
- #fetch_stats ⇒ Object
-
#recalculate_stats_interval ⇒ Object
Could be configurable, multisite need to support it.
- #refresh_stats ⇒ Object
- #stats_cache_key ⇒ Object
Instance Method Details
#fetch_cached_stats ⇒ Object
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_stats ⇒ Object
11 12 13 |
# File 'app/models/concerns/stats_cacheable.rb', line 11 def fetch_stats raise "Not implemented." end |
#recalculate_stats_interval ⇒ Object
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_stats ⇒ Object
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_key ⇒ Object
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 |