Method: M4DBI::Model.cached_fetch

Defined in:
lib/m4dbi/model.rb

.cached_fetch(cache_id, *args) ⇒ Object

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.

Parameters:

  • cache_id (String)

    A unique key identifying the cache to use.



46
47
48
49
50
51
52
53
# File 'lib/m4dbi/model.rb', line 46

def self.cached_fetch( cache_id, *args )
  if args.size > 1
    self[*args]
  else
    cache = Thread.current["m4dbi_cache_#{cache_id}_#{self.table}"] ||= Hash.new
    cache[*args] ||= self[*args]
  end
end