second_level_cache 2.2.1 → 2.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +1 -0
- data/lib/second_level_cache/active_record/finder_methods.rb +26 -1
- data/lib/second_level_cache/version.rb +1 -1
- data/test/finder_methods_test.rb +14 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 88a2a566c9af218fbcb4ba47cde3b0dddfcedc2b
|
4
|
+
data.tar.gz: 36e45a2c4efa464094022cab997b0ece390d164b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e501d209a3b2f6d9790fc813a558cea3a944457fdbda0b0d657835e30193a4592585e0a22b8f9e957298cf381e3bc902832ee11eecc69e323432d26ff934597
|
7
|
+
data.tar.gz: 0051c2f3c1e1110dc7088ffb2b1451e095a7872291e8efc04e42ecf68bb6fdcbfe7545e0e3d71379902495d488b5f562871dde3c3f0a148600a24db25329ddf2
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -2,7 +2,7 @@ module SecondLevelCache
|
|
2
2
|
module ActiveRecord
|
3
3
|
module FinderMethods
|
4
4
|
# TODO: find_some
|
5
|
-
#
|
5
|
+
# http://api.rubyonrails.org/classes/ActiveRecord/FinderMethods.html#method-i-find_one
|
6
6
|
#
|
7
7
|
# Cacheable:
|
8
8
|
#
|
@@ -34,6 +34,31 @@ module SecondLevelCache
|
|
34
34
|
record
|
35
35
|
end
|
36
36
|
|
37
|
+
# http://api.rubyonrails.org/classes/ActiveRecord/FinderMethods.html#method-i-first
|
38
|
+
#
|
39
|
+
# Cacheable:
|
40
|
+
#
|
41
|
+
# User.where(id: 1).first
|
42
|
+
# User.where(id: 1).last
|
43
|
+
#
|
44
|
+
# Uncacheable:
|
45
|
+
#
|
46
|
+
# User.where(name: 'foo').first
|
47
|
+
# User.where(age: 18).first
|
48
|
+
#
|
49
|
+
def first(limit = nil)
|
50
|
+
return super(limit) if limit.to_i > 1
|
51
|
+
# only have primary_key condition in where
|
52
|
+
if where_values_hash.length == 1 && where_values_hash.key?(primary_key)
|
53
|
+
record = @klass.read_second_level_cache(where_values_hash[primary_key])
|
54
|
+
return record if record
|
55
|
+
end
|
56
|
+
|
57
|
+
record = super(limit)
|
58
|
+
record.write_second_level_cache if record
|
59
|
+
record
|
60
|
+
end
|
61
|
+
|
37
62
|
private
|
38
63
|
|
39
64
|
def cachable?
|
data/test/finder_methods_test.rb
CHANGED
@@ -40,4 +40,18 @@ class FinderMethodsTest < ActiveSupport::TestCase
|
|
40
40
|
end
|
41
41
|
refute_equal @user.name, @from_db.name
|
42
42
|
end
|
43
|
+
|
44
|
+
def test_where_and_first_should_with_cache
|
45
|
+
@user.write_second_level_cache
|
46
|
+
assert_no_queries do
|
47
|
+
assert_equal @user, User.where(id: @user.id).first
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_where_and_last_should_with_cache
|
52
|
+
@user.write_second_level_cache
|
53
|
+
assert_no_queries do
|
54
|
+
assert_equal @user, User.where(id: @user.id).last
|
55
|
+
end
|
56
|
+
end
|
43
57
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: second_level_cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2.
|
4
|
+
version: 2.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hooopo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
11
|
+
date: 2016-02-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -187,7 +187,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
187
187
|
version: '0'
|
188
188
|
requirements: []
|
189
189
|
rubyforge_project:
|
190
|
-
rubygems_version: 2.
|
190
|
+
rubygems_version: 2.4.5.1
|
191
191
|
signing_key:
|
192
192
|
specification_version: 4
|
193
193
|
summary: 'SecondLevelCache is a write-through and read-through caching library inspired
|