rcache 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rcache/arel.rb +5 -0
- data/lib/rcache/query_cache.rb +5 -7
- data/lib/rcache/query_methods.rb +3 -2
- data/lib/rcache/relation.rb +7 -2
- data/lib/rcache/version.rb +1 -1
- metadata +6 -5
data/lib/rcache/arel.rb
ADDED
data/lib/rcache/query_cache.rb
CHANGED
@@ -1,12 +1,10 @@
|
|
1
1
|
module ActiveRecord
|
2
2
|
module ConnectionAdapters # :nodoc:
|
3
3
|
module QueryCache
|
4
|
-
attr_accessor :rcache_value
|
5
|
-
|
6
4
|
def select_all(arel, name = nil, binds = [])
|
7
|
-
if
|
5
|
+
if arel.rcache_value && !locked?(arel) && (arel.rcache_value[:expires_in] || Rcache.expires_in).to_i > 0
|
8
6
|
sql = to_sql(arel, binds)
|
9
|
-
redis_cache_sql(sql, binds) { super(sql, name, binds) }
|
7
|
+
redis_cache_sql(arel.rcache_value, sql, binds) { super(sql, name, binds) }
|
10
8
|
elsif @query_cache_enabled && !locked?(arel)
|
11
9
|
sql = to_sql(arel, binds)
|
12
10
|
cache_sql(sql, binds) { super(sql, name, binds) }
|
@@ -17,14 +15,14 @@ module ActiveRecord
|
|
17
15
|
|
18
16
|
private
|
19
17
|
|
20
|
-
def redis_cache_sql(sql, binds)
|
18
|
+
def redis_cache_sql(rcache_value, sql, binds)
|
21
19
|
[:redis, :expires_in, :log_cached_queries, :key_prefix].each do |attr|
|
22
|
-
instance_variable_set("@#{attr}",
|
20
|
+
instance_variable_set("@#{attr}", rcache_value.has_key?(attr) ? rcache_value[attr] : Rcache.send(attr))
|
23
21
|
end
|
24
22
|
|
25
23
|
result =
|
26
24
|
# return from memory
|
27
|
-
if @query_cache[sql].key?(binds)
|
25
|
+
if @query_cache_enabled && @query_cache[sql].key?(binds)
|
28
26
|
ActiveSupport::Notifications.instrument("sql.active_record", :sql => sql, :binds => binds, :name => "CACHE", :connection_id => object_id) if @log_cached_queries
|
29
27
|
@query_cache[sql][binds]
|
30
28
|
# write to memory from redis and return
|
data/lib/rcache/query_methods.rb
CHANGED
data/lib/rcache/relation.rb
CHANGED
@@ -1,10 +1,14 @@
|
|
1
1
|
module ActiveRecord
|
2
2
|
class Relation
|
3
|
+
attr_accessor :rcache_value
|
4
|
+
|
3
5
|
def exec_queries
|
4
6
|
return @records if loaded?
|
5
7
|
|
6
8
|
default_scoped = with_default_scope
|
7
9
|
|
10
|
+
arel.rcache_value = rcache_value
|
11
|
+
|
8
12
|
if default_scoped.equal?(self)
|
9
13
|
@records = if @readonly_value.nil? && !@klass.locking_enabled?
|
10
14
|
eager_loading? ? find_with_associations : @klass.find_by_sql(arel, @bind_values)
|
@@ -18,7 +22,7 @@ module ActiveRecord
|
|
18
22
|
preload += @includes_values unless eager_loading?
|
19
23
|
preload.each do |associations|
|
20
24
|
# this line distincts only
|
21
|
-
ActiveRecord::Associations::Preloader.new(@records, associations, :rcache_value =>
|
25
|
+
ActiveRecord::Associations::Preloader.new(@records, associations, :rcache_value => rcache_value).run
|
22
26
|
end
|
23
27
|
|
24
28
|
# @readonly_value is true only if set explicitly. @implicit_readonly is true if there
|
@@ -28,7 +32,8 @@ module ActiveRecord
|
|
28
32
|
else
|
29
33
|
@records = default_scoped.to_a
|
30
34
|
end
|
31
|
-
|
35
|
+
|
36
|
+
|
32
37
|
@loaded = true
|
33
38
|
@records
|
34
39
|
end
|
data/lib/rcache/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rcache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-12-
|
12
|
+
date: 2013-12-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
@@ -72,6 +72,7 @@ files:
|
|
72
72
|
- README.md
|
73
73
|
- Rakefile
|
74
74
|
- lib/rcache.rb
|
75
|
+
- lib/rcache/arel.rb
|
75
76
|
- lib/rcache/association.rb
|
76
77
|
- lib/rcache/preloader.rb
|
77
78
|
- lib/rcache/query_cache.rb
|
@@ -95,7 +96,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
95
96
|
version: '0'
|
96
97
|
segments:
|
97
98
|
- 0
|
98
|
-
hash:
|
99
|
+
hash: 2546036101043435318
|
99
100
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
101
|
none: false
|
101
102
|
requirements:
|
@@ -104,10 +105,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
105
|
version: '0'
|
105
106
|
segments:
|
106
107
|
- 0
|
107
|
-
hash:
|
108
|
+
hash: 2546036101043435318
|
108
109
|
requirements: []
|
109
110
|
rubyforge_project:
|
110
|
-
rubygems_version: 1.8.
|
111
|
+
rubygems_version: 1.8.25
|
111
112
|
signing_key:
|
112
113
|
specification_version: 3
|
113
114
|
summary: ActiveRecord redis query cache
|