0.0
No commit activity in last 3 years
No release in over 3 years
Counter cache on steroids - requires a bit of configuration, but then simply saves counter data.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 0.9.2
>= 0

Runtime

>= 0
 Project Readme

counter-cachier

usage

counter cachier is a generic counter caching solution (using redis) for stuff where ActiveRecord's counter cache just does not cut it. i.e. when the counter is on a complex association, etc.

usage is pretty simple, simply include CounterCachier in the class you wish to use it on, and define counter cachiers:

class User
  include CounterCachier

  counter_cachier :approved_posts_count do |user|
    user.posts.approved.count
  end
end

the block's argument is the object you're making the calculations for (i.e. an instance of User), the value returned in the block will be the new counter. From this moment, two new methods are added to User - approved_posts_count and recalc_approved_posts_count.

user = User.first
user.approved_posts_count #=> 10
#...user adds an approved post...
user.recalc_approved_posts_count #=> 11, but it actually recalculates and pushes the number into redis.

installation

in your gemfile gem "counter_cachier"

in an initializer:

CounterCachier.redis = Redis.new(redis_configuration)

you can skip this if you've got the $redis global.