Class: ActiveRecord::QueryCache
- Inherits:
-
Object
- Object
- ActiveRecord::QueryCache
show all
- Defined in:
- lib/active_record/query_cache.rb
Overview
Instance Method Summary
collapse
Constructor Details
#initialize(connection) ⇒ QueryCache
Returns a new instance of QueryCache.
3
4
5
6
|
# File 'lib/active_record/query_cache.rb', line 3
def initialize(connection)
@connection = connection
@query_cache = {}
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *arguments, &proc) ⇒ Object
40
41
42
|
# File 'lib/active_record/query_cache.rb', line 40
def method_missing(method, *arguments, &proc)
@connection.send(method, *arguments, &proc)
end
|
Instance Method Details
#clear_query_cache ⇒ Object
8
9
10
|
# File 'lib/active_record/query_cache.rb', line 8
def clear_query_cache
@query_cache = {}
end
|
#columns(table_name, name = nil) ⇒ Object
20
21
22
|
# File 'lib/active_record/query_cache.rb', line 20
def columns(table_name, name = nil)
@query_cache["SHOW FIELDS FROM #{table_name}"] ||= @connection.columns(table_name, name)
end
|
#delete(sql, name = nil) ⇒ Object
34
35
36
37
|
# File 'lib/active_record/query_cache.rb', line 34
def delete(sql, name = nil)
clear_query_cache
@connection.delete(sql, name)
end
|
#insert(sql, name = nil, pk = nil, id_value = nil) ⇒ Object
24
25
26
27
|
# File 'lib/active_record/query_cache.rb', line 24
def insert(sql, name = nil, pk = nil, id_value = nil)
clear_query_cache
@connection.insert(sql, name, pk, id_value)
end
|
#select_all(sql, name = nil) ⇒ Object
12
13
14
|
# File 'lib/active_record/query_cache.rb', line 12
def select_all(sql, name = nil)
(@query_cache[sql] ||= @connection.select_all(sql, name)).dup
end
|
#select_one(sql, name = nil) ⇒ Object
16
17
18
|
# File 'lib/active_record/query_cache.rb', line 16
def select_one(sql, name = nil)
@query_cache[sql] ||= @connection.select_one(sql, name)
end
|
#update(sql, name = nil) ⇒ Object
29
30
31
32
|
# File 'lib/active_record/query_cache.rb', line 29
def update(sql, name = nil)
clear_query_cache
@connection.update(sql, name)
end
|