Created
October 3, 2014 13:30
-
-
Save dv/71c424a4c5fdbb5160ba to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Coder < ActiveRecord::Base | |
after_save :clear_caches | |
private | |
def clear_caches | |
Stats.expire_coder_punten | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Stats | |
def punten | |
coder_punten + issue_punten | |
end | |
def expire_coder_punten | |
Rails.cache.delete('stats', 'coder_punten') | |
end | |
def expire_issue_punten | |
Rails.cache.delete('stats', 'issue_punten') | |
end | |
def coder_punten | |
Rails.cache.fetch('stats', 'coder_punten') { Coder.sum(:punten) } | |
end | |
def issue_punten | |
Rails.cache.fetch('stats', 'issue_punten') { Issue.sum(:punten) } | |
end | |
class << self | |
def method_missing(name, *args, &block) | |
self.new.send(name, *args, &block) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment