second_level_cache 2.1.1 → 2.1.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/README.md +1 -1
- data/lib/second_level_cache/active_record/base.rb +1 -1
- data/lib/second_level_cache/active_record/core.rb +22 -0
- data/lib/second_level_cache/active_record/persistence.rb +2 -2
- data/lib/second_level_cache/active_record.rb +1 -0
- data/lib/second_level_cache/record_marshal.rb +1 -3
- data/lib/second_level_cache/version.rb +1 -1
- data/lib/second_level_cache.rb +1 -0
- data/test/base_test.rb +2 -2
- data/test/fetch_by_uniq_key_test.rb +1 -1
- data/test/model/account.rb +7 -7
- data/test/model/animal.rb +1 -1
- data/test/model/topic.rb +1 -1
- data/test/model/user.rb +1 -1
- data/test/test_helper.rb +4 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fb07072700dce834842d9754944d53a7979dee6e
|
4
|
+
data.tar.gz: af6487f82394c38724fb9b7dd5b74bcfab99c461
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c3c0b7fee0c8d0a3438293a9f2ce74162ef64a42efa52022cb68a71ef8c84c7b54b371c1563f6a5a2022c64621db43905d709ea995537d2ae262798bc004809
|
7
|
+
data.tar.gz: ad86ef72719f22ea78ba9c20e968d06ce8de57b9969aca6f4a2ac937edb6511892cceb80407623bb7131f9c2c4421d7528c99703d982dfab2a7d6e0722344361
|
data/README.md
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
module SecondLevelCache
|
3
|
+
module ActiveRecord
|
4
|
+
module Core
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
class << self
|
9
|
+
alias_method_chain :find, :cache
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
module ClassMethods
|
15
|
+
def find_with_cache(*ids)
|
16
|
+
return all.find(ids.first) if ids.size == 1 && ids.first.is_a?(Fixnum)
|
17
|
+
find_without_cache(*ids)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -21,8 +21,8 @@ module SecondLevelCache
|
|
21
21
|
reload_without_second_level_cache(options)
|
22
22
|
end
|
23
23
|
|
24
|
-
def touch_with_second_level_cache(
|
25
|
-
touch_without_second_level_cache(
|
24
|
+
def touch_with_second_level_cache(*names)
|
25
|
+
touch_without_second_level_cache(*names).tap{update_second_level_cache}
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
require 'second_level_cache/active_record/base'
|
3
|
+
require 'second_level_cache/active_record/core'
|
3
4
|
require 'second_level_cache/active_record/fetch_by_uniq_key'
|
4
5
|
require 'second_level_cache/active_record/finder_methods'
|
5
6
|
require 'second_level_cache/active_record/persistence'
|
@@ -19,9 +19,7 @@ module RecordMarshal
|
|
19
19
|
# load a cached record
|
20
20
|
def load(serialized)
|
21
21
|
return unless serialized
|
22
|
-
|
23
|
-
record.init_with('attributes' => serialized[1])
|
24
|
-
record
|
22
|
+
serialized[0].constantize.instantiate(serialized[1])
|
25
23
|
end
|
26
24
|
|
27
25
|
def load_multi(serializeds)
|
data/lib/second_level_cache.rb
CHANGED
@@ -24,6 +24,7 @@ module SecondLevelCache
|
|
24
24
|
@second_level_cache_options[:expires_in] ||= 1.week
|
25
25
|
@second_level_cache_options[:version] ||= 0
|
26
26
|
relation.class.send :include, SecondLevelCache::ActiveRecord::FinderMethods
|
27
|
+
include SecondLevelCache::ActiveRecord::Core if /^4\.2\./.match(::ActiveRecord.version.version)
|
27
28
|
end
|
28
29
|
|
29
30
|
def second_level_cache_enabled?
|
data/test/base_test.rb
CHANGED
@@ -22,10 +22,10 @@ class BaseTest < ActiveSupport::TestCase
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def test_should_expire_cache_when_update_counters
|
25
|
-
assert_equal @user.books_count
|
25
|
+
assert_equal 0, @user.books_count
|
26
26
|
@user.books.create
|
27
27
|
assert_nil User.read_second_level_cache(@user.id)
|
28
28
|
user = User.find(@user.id)
|
29
|
-
assert_equal
|
29
|
+
assert_equal 1, user.books_count
|
30
30
|
end
|
31
31
|
end
|
@@ -17,7 +17,7 @@ class FetchByUinqKeyTest < ActiveSupport::TestCase
|
|
17
17
|
def test_should_query_from_db_using_primary_key
|
18
18
|
Post.fetch_by_uniq_keys(:topic_id => 2, :slug => "foobar")
|
19
19
|
@post.expire_second_level_cache
|
20
|
-
assert_sql
|
20
|
+
assert_sql(/SELECT\s+"posts".* FROM "posts"\s+WHERE "posts"."id" = \? LIMIT 1/) do
|
21
21
|
Post.fetch_by_uniq_keys(:topic_id => 2, :slug => "foobar")
|
22
22
|
end
|
23
23
|
end
|
data/test/model/account.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
|
-
ActiveRecord::Base.connection.create_table(:accounts, :
|
3
|
-
t.integer
|
4
|
-
t.string
|
5
|
-
t.integer
|
6
|
-
t.timestamps
|
2
|
+
ActiveRecord::Base.connection.create_table(:accounts, force: true) do |t|
|
3
|
+
t.integer :age
|
4
|
+
t.string :site
|
5
|
+
t.integer :user_id
|
6
|
+
t.timestamps null: false
|
7
7
|
end
|
8
8
|
|
9
9
|
class Account < ActiveRecord::Base
|
10
|
-
acts_as_cached(:
|
10
|
+
acts_as_cached(expires_in: 3.day)
|
11
11
|
belongs_to :user
|
12
|
-
end
|
12
|
+
end
|
data/test/model/animal.rb
CHANGED
data/test/model/topic.rb
CHANGED
data/test/model/user.rb
CHANGED
data/test/test_helper.rb
CHANGED
@@ -4,8 +4,11 @@ require 'minitest/autorun'
|
|
4
4
|
require 'active_support/test_case'
|
5
5
|
require 'active_record_test_case_helper'
|
6
6
|
require 'database_cleaner'
|
7
|
-
|
8
7
|
require 'active_record'
|
8
|
+
|
9
|
+
ActiveRecord::Base.raise_in_transactional_callbacks = true if ActiveRecord::Base.respond_to?(:raise_in_transactional_callbacks=)
|
10
|
+
ActiveSupport.test_order = :sorted if ActiveSupport.respond_to?(:test_order=)
|
11
|
+
|
9
12
|
require 'second_level_cache'
|
10
13
|
|
11
14
|
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
|
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.1.
|
4
|
+
version: 2.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hooopo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -108,6 +108,7 @@ files:
|
|
108
108
|
- lib/second_level_cache/active_record.rb
|
109
109
|
- lib/second_level_cache/active_record/base.rb
|
110
110
|
- lib/second_level_cache/active_record/belongs_to_association.rb
|
111
|
+
- lib/second_level_cache/active_record/core.rb
|
111
112
|
- lib/second_level_cache/active_record/fetch_by_uniq_key.rb
|
112
113
|
- lib/second_level_cache/active_record/finder_methods.rb
|
113
114
|
- lib/second_level_cache/active_record/has_one_association.rb
|