Module: Occurro::CachedCounter
- Defined in:
- lib/occurro/cached_counter.rb
Class Method Summary collapse
-
.increment_counter(model) ⇒ Object
Increments the counter based on the model counter_cache option.
Class Method Details
.increment_counter(model) ⇒ Object
Increments the counter based on the model counter_cache option. If the counter_cache limit is not reached, it will store the value on Rails.cache, and will submit it to persistence only when there are as many entries as the counter_cache value
9 10 11 12 13 14 |
# File 'lib/occurro/cached_counter.rb', line 9 def self.increment_counter(model) cached_counts = Rails.cache.read(key_name(model)).to_i + 1 return update_cached_counter(model, cached_counts) if cached_counts < model.class.counter_cache update_cached_counter(model, 0) Occurro::Jobs::Sender.increment_counters_job(model, cached_counts) end |