second_level_cache 2.0.0 → 2.1.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -0
- data/README.md +7 -1
- data/lib/second_level_cache/active_record/preloader.rb +2 -3
- data/lib/second_level_cache/version.rb +1 -1
- data/second_level_cache.gemspec +3 -3
- data/test/active_record/base_test.rb +1 -1
- data/test/active_record/belongs_to_association_test.rb +1 -1
- data/test/active_record/fetch_by_uniq_key_test.rb +2 -2
- data/test/active_record/finder_methods_test.rb +3 -3
- data/test/active_record/has_one_association_test.rb +1 -1
- data/test/active_record/persistence_test.rb +1 -1
- data/test/active_record/polymorphic_association_test.rb +1 -1
- data/test/active_record/preloader_test.rb +1 -1
- data/test/active_record/second_level_cache_test.rb +2 -2
- data/test/active_record/test_helper.rb +6 -1
- data/test/record_marshal_test.rb +1 -1
- data/test/require_test.rb +1 -1
- data/test/test_helper.rb +1 -1
- metadata +28 -17
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -79,7 +79,7 @@ Only `SELECT *` query will be cached:
|
|
79
79
|
User.select("id, name").find(1)
|
80
80
|
```
|
81
81
|
|
82
|
-
Notice
|
82
|
+
## Notice
|
83
83
|
|
84
84
|
* SecondLevelCache cache by model name and id, so only find_one query will work.
|
85
85
|
* Only equal conditions query WILL get cache; and SQL string query like `User.where("name = 'Hooopo'").find(1)` WILL NOT work.
|
@@ -101,6 +101,12 @@ end # <- Cache write
|
|
101
101
|
Rails.logger.info "info"
|
102
102
|
```
|
103
103
|
|
104
|
+
* If you are using SecondLevelCache with database_cleaner, you should set cleaning strategy to `:truncation`:
|
105
|
+
|
106
|
+
```ruby
|
107
|
+
DatabaseCleaner.strategy = :truncation
|
108
|
+
```
|
109
|
+
|
104
110
|
## Configure
|
105
111
|
|
106
112
|
In production env, we recommend to use [Dalli](https://github.com/mperham/dalli) as Rails cache store.
|
@@ -17,12 +17,11 @@ module SecondLevelCache
|
|
17
17
|
|
18
18
|
map_cache_keys = ids.map{|id| klass.second_level_cache_key(id)}
|
19
19
|
records_from_cache = ::SecondLevelCache.cache_store.read_multi(*map_cache_keys)
|
20
|
-
|
21
20
|
# NOTICE
|
22
21
|
# Rails.cache.read_multi return hash that has keys only hitted.
|
23
22
|
# eg. Rails.cache.read_multi(1,2,3) => {2 => hit_value, 3 => hit_value}
|
24
|
-
hitted_ids = records_from_cache.map{|key, _| key.split("/")[2]}
|
25
|
-
missed_ids = ids - hitted_ids
|
23
|
+
hitted_ids = records_from_cache.map{|key, _| key.split("/")[2].to_i}
|
24
|
+
missed_ids = ids.map{|x| x.to_i} - hitted_ids
|
26
25
|
|
27
26
|
::SecondLevelCache::Config.logger.info "missed ids -> #{missed_ids.inspect} | hitted ids -> #{hitted_ids.inspect}"
|
28
27
|
|
data/second_level_cache.gemspec
CHANGED
@@ -30,10 +30,10 @@ Gem::Specification.new do |gem|
|
|
30
30
|
gem.require_paths = ["lib"]
|
31
31
|
gem.version = SecondLevelCache::VERSION
|
32
32
|
|
33
|
-
gem.add_runtime_dependency "activesupport", ["
|
33
|
+
gem.add_runtime_dependency "activesupport", ["> 4.0.0", "< 5.0"]
|
34
34
|
|
35
|
-
gem.add_development_dependency "activerecord", ["
|
35
|
+
gem.add_development_dependency "activerecord", ["> 4.0.0", "< 5.0"]
|
36
36
|
gem.add_development_dependency "sqlite3"
|
37
37
|
gem.add_development_dependency "rake"
|
38
|
-
gem.add_development_dependency "database_cleaner", "~> 1.
|
38
|
+
gem.add_development_dependency "database_cleaner", "~> 1.2.0"
|
39
39
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
require 'active_record/test_helper'
|
3
3
|
|
4
|
-
class ActiveRecord::BelongsToAssociationTest < Test
|
4
|
+
class ActiveRecord::BelongsToAssociationTest < Minitest::Test
|
5
5
|
def setup
|
6
6
|
@user = User.create :name => 'csdn', :email => 'test@csdn.com'
|
7
7
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
require 'active_record/test_helper'
|
3
3
|
|
4
|
-
class ActiveRecord::FetchByUinqKeyTest < Test
|
4
|
+
class ActiveRecord::FetchByUinqKeyTest < Minitest::Test
|
5
5
|
def setup
|
6
6
|
DatabaseCleaner[:active_record].start
|
7
7
|
@user = User.create :name => 'hooopo', :email => 'hoooopo@gmail.com'
|
@@ -23,7 +23,7 @@ class ActiveRecord::FetchByUinqKeyTest < Test::Unit::TestCase
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def test_should_fail_when_fetch_by_uniq_key_with_bang_method
|
26
|
-
|
26
|
+
assert_raises(ActiveRecord::RecordNotFound) do
|
27
27
|
User.fetch_by_uniq_key!(@user.name + "not_exist", :name)
|
28
28
|
end
|
29
29
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
require 'active_record/test_helper'
|
3
3
|
|
4
|
-
class ActiveRecord::FinderMethodsTest < Test
|
4
|
+
class ActiveRecord::FinderMethodsTest < Minitest::Test
|
5
5
|
def setup
|
6
6
|
@user = User.create :name => 'csdn', :email => 'test@csdn.com'
|
7
7
|
end
|
@@ -28,7 +28,7 @@ class ActiveRecord::FinderMethodsTest < Test::Unit::TestCase
|
|
28
28
|
def test_should_NOT_find_from_cache_when_select_speical_columns
|
29
29
|
@user.write_second_level_cache
|
30
30
|
only_id_user = User.select("id").find(@user.id)
|
31
|
-
|
31
|
+
assert_raises(ActiveModel::MissingAttributeError) do
|
32
32
|
only_id_user.name
|
33
33
|
end
|
34
34
|
end
|
@@ -39,6 +39,6 @@ class ActiveRecord::FinderMethodsTest < Test::Unit::TestCase
|
|
39
39
|
User.without_second_level_cache do
|
40
40
|
@from_db = User.find(@user.id)
|
41
41
|
end
|
42
|
-
|
42
|
+
refute_equal @user.name, @from_db.name
|
43
43
|
end
|
44
44
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
require 'active_record/test_helper'
|
3
3
|
|
4
|
-
class ActiveRecord::HasOneAssociationTest < Test
|
4
|
+
class ActiveRecord::HasOneAssociationTest < Minitest::Test
|
5
5
|
def setup
|
6
6
|
@user = User.create :name => 'hooopo', :email => 'hoooopo@gmail.com'
|
7
7
|
@account = @user.create_account
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
require 'active_record/test_helper'
|
3
3
|
|
4
|
-
class ActiveRecord::PersistenceTest < Test
|
4
|
+
class ActiveRecord::PersistenceTest < Minitest::Test
|
5
5
|
def setup
|
6
6
|
@user = User.create :name => 'csdn', :email => 'test@csdn.com'
|
7
7
|
@topic = Topic.create :title => "csdn"
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
require 'active_record/test_helper'
|
3
3
|
|
4
|
-
class ActiveRecord::PolymorphicAssociationTest < Test
|
4
|
+
class ActiveRecord::PolymorphicAssociationTest < Minitest::Test
|
5
5
|
def setup
|
6
6
|
@user = User.create :name => 'csdn', :email => 'test@csdn.com'
|
7
7
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
require 'active_record/test_helper'
|
3
3
|
|
4
|
-
class ActiveRecord::PreloaderTest < Test
|
4
|
+
class ActiveRecord::PreloaderTest < Minitest::Test
|
5
5
|
def setup
|
6
6
|
DatabaseCleaner[:active_record].start
|
7
7
|
@topic1 = Topic.create :title => "title1", :body => "body1"
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
require 'active_record/test_helper'
|
3
3
|
|
4
|
-
class ActiveRecord::SecondLevelCacheTest < Test
|
4
|
+
class ActiveRecord::SecondLevelCacheTest < Minitest::Test
|
5
5
|
def setup
|
6
6
|
@user = User.create :name => 'csdn', :email => 'test@csdn.com'
|
7
7
|
end
|
@@ -12,7 +12,7 @@ class ActiveRecord::SecondLevelCacheTest < Test::Unit::TestCase
|
|
12
12
|
|
13
13
|
def test_should_write_and_read_cache
|
14
14
|
@user.write_second_level_cache
|
15
|
-
|
15
|
+
refute_nil User.read_second_level_cache(@user.id)
|
16
16
|
@user.expire_second_level_cache
|
17
17
|
assert_nil User.read_second_level_cache(@user.id)
|
18
18
|
end
|
@@ -15,13 +15,18 @@ def close_test_db_connect
|
|
15
15
|
ActiveRecord::Base.connection.disconnect!
|
16
16
|
end
|
17
17
|
|
18
|
-
class Test
|
18
|
+
class Minitest::Test
|
19
19
|
def no_connection
|
20
20
|
close_test_db_connect
|
21
21
|
assert_nothing_raised { yield }
|
22
22
|
ensure
|
23
23
|
open_test_db_connect
|
24
24
|
end
|
25
|
+
|
26
|
+
|
27
|
+
def assert_nothing_raised(*)
|
28
|
+
yield
|
29
|
+
end
|
25
30
|
|
26
31
|
def teardown
|
27
32
|
$sql_logger = nil
|
data/test/record_marshal_test.rb
CHANGED
data/test/require_test.rb
CHANGED
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,48 +1,60 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: second_level_cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
5
|
-
prerelease:
|
4
|
+
version: 2.1.0.rc1
|
5
|
+
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Hooopo
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2014-02-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
|
-
- -
|
19
|
+
- - ! '>'
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 4.0.0
|
22
|
+
- - <
|
20
23
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
24
|
+
version: '5.0'
|
22
25
|
type: :runtime
|
23
26
|
prerelease: false
|
24
27
|
version_requirements: !ruby/object:Gem::Requirement
|
25
28
|
none: false
|
26
29
|
requirements:
|
27
|
-
- -
|
30
|
+
- - ! '>'
|
28
31
|
- !ruby/object:Gem::Version
|
29
|
-
version: 4.0.0
|
32
|
+
version: 4.0.0
|
33
|
+
- - <
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '5.0'
|
30
36
|
- !ruby/object:Gem::Dependency
|
31
37
|
name: activerecord
|
32
38
|
requirement: !ruby/object:Gem::Requirement
|
33
39
|
none: false
|
34
40
|
requirements:
|
35
|
-
- -
|
41
|
+
- - ! '>'
|
36
42
|
- !ruby/object:Gem::Version
|
37
|
-
version: 4.0.0
|
43
|
+
version: 4.0.0
|
44
|
+
- - <
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '5.0'
|
38
47
|
type: :development
|
39
48
|
prerelease: false
|
40
49
|
version_requirements: !ruby/object:Gem::Requirement
|
41
50
|
none: false
|
42
51
|
requirements:
|
43
|
-
- -
|
52
|
+
- - ! '>'
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 4.0.0
|
55
|
+
- - <
|
44
56
|
- !ruby/object:Gem::Version
|
45
|
-
version:
|
57
|
+
version: '5.0'
|
46
58
|
- !ruby/object:Gem::Dependency
|
47
59
|
name: sqlite3
|
48
60
|
requirement: !ruby/object:Gem::Requirement
|
@@ -82,7 +94,7 @@ dependencies:
|
|
82
94
|
requirements:
|
83
95
|
- - ~>
|
84
96
|
- !ruby/object:Gem::Version
|
85
|
-
version: 1.
|
97
|
+
version: 1.2.0
|
86
98
|
type: :development
|
87
99
|
prerelease: false
|
88
100
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -90,7 +102,7 @@ dependencies:
|
|
90
102
|
requirements:
|
91
103
|
- - ~>
|
92
104
|
- !ruby/object:Gem::Version
|
93
|
-
version: 1.
|
105
|
+
version: 1.2.0
|
94
106
|
description: Write Through and Read Through caching library inspired by CacheMoney
|
95
107
|
and cache_fu, support ActiveRecord 4.
|
96
108
|
email:
|
@@ -151,12 +163,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
151
163
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
152
164
|
none: false
|
153
165
|
requirements:
|
154
|
-
- - ! '
|
166
|
+
- - ! '>'
|
155
167
|
- !ruby/object:Gem::Version
|
156
|
-
version:
|
168
|
+
version: 1.3.1
|
157
169
|
requirements: []
|
158
170
|
rubyforge_project:
|
159
|
-
rubygems_version: 1.8.
|
171
|
+
rubygems_version: 1.8.23
|
160
172
|
signing_key:
|
161
173
|
specification_version: 3
|
162
174
|
summary: ! 'SecondLevelCache is a write-through and read-through caching library inspired
|
@@ -185,4 +197,3 @@ test_files:
|
|
185
197
|
- test/record_marshal_test.rb
|
186
198
|
- test/require_test.rb
|
187
199
|
- test/test_helper.rb
|
188
|
-
has_rdoc:
|