-
-
Save phildionne/6728341 to your computer and use it in GitHub Desktop.
This file contains 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
module Cachemire | |
extend ActiveSupport::Concern | |
included do | |
class_attribute :cache_store | |
end | |
module ClassMethods | |
private | |
def cache_result(&block) | |
cache_store.fetch("#{object_id}_#{caller_locations(1,1)[0].label}") do | |
block.call | |
end | |
end | |
end | |
private | |
def cache_result(&block) | |
cache_store.fetch("#{object_id}_#{caller_locations(1,1)[0].label}") do | |
block.call | |
end | |
end | |
end |
This file contains 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 World | |
include Cachemire | |
self.cache_store = ActiveSupport::Cache::MemoryStore.new | |
def self.get_population_count | |
cache_result do | |
# Intense stuff... | |
end | |
end | |
def get_population_count | |
cache_result do | |
# Intense stuff... | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment