5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/finder.rb', line 5
def self.included(base)
base.instance_eval do
validates_uniqueness_of finder_attribute
cattr_accessor :cache_store
self.cache_store ||= ActiveSupport::Cache::MemoryStore.new
def self.[](token)
cache_store.fetch("[]:#{token}", :force => Rubysolo::Hashdown.force_cache_miss?) {
returning find(:first, :conditions => { finder_attribute => token.to_s}) do |record|
raise "Could not find #{self.class_name} with #{finder_attribute} '#{token}'" unless record
end
}
end
end
end
|