diff options
author | Tobias Lütke <tobias.luetke@gmail.com> | 2007-02-20 23:42:04 +0000 |
---|---|---|
committer | Tobias Lütke <tobias.luetke@gmail.com> | 2007-02-20 23:42:04 +0000 |
commit | b5419cd66ea160d1ee94f3ca521bb44adf3a21ca (patch) | |
tree | 79ffdd2411ff623542c9c5a1779dad9f980843b5 /activerecord/lib/active_record | |
parent | e1056530665d5c8eed2c325157fbb88553eb2678 (diff) | |
download | rails-b5419cd66ea160d1ee94f3ca521bb44adf3a21ca.tar.gz rails-b5419cd66ea160d1ee94f3ca521bb44adf3a21ca.tar.bz2 rails-b5419cd66ea160d1ee94f3ca521bb44adf3a21ca.zip |
You can now use cache in instance hierachies. This allows ActiveRecord::Base.cache { } usage to cache everything
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6179 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/query_cache.rb | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/query_cache.rb b/activerecord/lib/active_record/query_cache.rb index 415b25e096..e2f5c1bd88 100644 --- a/activerecord/lib/active_record/query_cache.rb +++ b/activerecord/lib/active_record/query_cache.rb @@ -63,16 +63,28 @@ module ActiveRecord def query_caches (Thread.current[:query_cache] ||= {}) end + + def query_cache + if query_caches[self] + query_caches[self] + elsif superclass.respond_to?(:query_cache) + superclass.query_cache + end + end + + def query_cache=(cache) + query_caches[self] = cache + end def cache - query_caches[self] = QueryCache.new(connection) + self.query_cache = QueryCache.new(connection_without_query_cache) yield ensure - query_caches[self] = nil + self.query_cache = nil end def connection - query_caches[self] || connection_without_query_cache + query_cache || connection_without_query_cache end end end |