Skip to content

Commit

Permalink
Model.cached_fetch now requires a cache_id .
Browse files Browse the repository at this point in the history
  • Loading branch information
Pistos committed May 13, 2013
1 parent 094db36 commit 221af30
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/m4dbi/model.rb
Expand Up @@ -41,11 +41,12 @@ def self.[]( first_arg, *args )
# Acts like self.[] (read only), except it keeps a cache of the fetch
# results in memory for the lifetime of the thread. Useful for applications
# like web apps which create a new thread for each HTTP request.
def self.cached_fetch( *args )
# @param [String] cache_id A unique key identifying the cache to use.
def self.cached_fetch( cache_id, *args )
if args.size > 1
self[*args]
else
cache = Thread.current["m4dbi_cache_#{self.table}"] ||= Hash.new
cache = Thread.current["m4dbi_cache_#{cache_id}_#{self.table}"] ||= Hash.new
cache[*args] ||= self[*args]
end
end
Expand Down

0 comments on commit 221af30

Please sign in to comment.