second_level_cache 2.1.1 → 2.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3c1235017053004991468a6a2eb8661d8e9d82e7
4
- data.tar.gz: db06d8212c45306ba2b895765a2aa90a30e29569
3
+ metadata.gz: fb07072700dce834842d9754944d53a7979dee6e
4
+ data.tar.gz: af6487f82394c38724fb9b7dd5b74bcfab99c461
5
5
  SHA512:
6
- metadata.gz: 467e7aba16374a978b653ca9c4236214ad33d178b10643027b4e2adc45337016b292dc212ae6ce7985d2ac2794765ba9038583decaa000183e7ef081846b6038
7
- data.tar.gz: b66b78795b29cbabd3dc263c2a22f11681acf937dac404629af4d0b754e948926fea1e4730e1631a4d1b5c8069d2792b6e54d486cd2def0901c956b9cc746829
6
+ metadata.gz: 6c3c0b7fee0c8d0a3438293a9f2ce74162ef64a42efa52022cb68a71ef8c84c7b54b371c1563f6a5a2022c64621db43905d709ea995537d2ae262798bc004809
7
+ data.tar.gz: ad86ef72719f22ea78ba9c20e968d06ce8de57b9969aca6f4a2ac937edb6511892cceb80407623bb7131f9c2c4421d7528c99703d982dfab2a7d6e0722344361
data/README.md CHANGED
@@ -17,7 +17,7 @@ Write-Through: As objects are created, updated, and deleted, all of the caches a
17
17
  In your gem file:
18
18
 
19
19
  ```ruby
20
- gem "second_level_cache", "~> 2.1.1"
20
+ gem "second_level_cache", "~> 2.1.2"
21
21
  ```
22
22
 
23
23
  For ActiveRecord 3:
@@ -12,8 +12,8 @@ module SecondLevelCache
12
12
  class << self
13
13
  alias_method_chain :update_counters, :cache
14
14
  end
15
- end
16
15
 
16
+ end
17
17
 
18
18
  module ClassMethods
19
19
  def update_counters_with_cache(id, counters)
@@ -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(name = nil)
25
- touch_without_second_level_cache(name).tap{update_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
- record = serialized[0].constantize.allocate
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)
@@ -1,4 +1,4 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  module SecondLevelCache
3
- VERSION = "2.1.1"
3
+ VERSION = "2.1.2"
4
4
  end
@@ -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, 0
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 user.books_count, @user.books_count + 1
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 'SELECT "posts".* FROM "posts" WHERE "posts"."id" = ? LIMIT 1' do
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
@@ -1,12 +1,12 @@
1
1
  # -*- encoding : utf-8 -*-
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
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(:expires_in => 3.day)
10
+ acts_as_cached(expires_in: 3.day)
11
11
  belongs_to :user
12
- end
12
+ end
data/test/model/animal.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  ActiveRecord::Base.connection.create_table(:animals, force: true) do |t|
3
3
  t.string :type
4
4
  t.string :name
5
- t.timestamps
5
+ t.timestamps null: false
6
6
  end
7
7
 
8
8
  class Animal < ActiveRecord::Base
data/test/model/topic.rb CHANGED
@@ -3,7 +3,7 @@ ActiveRecord::Base.connection.create_table(:topics, :force => true) do |t|
3
3
  t.string :title
4
4
  t.text :body
5
5
 
6
- t.timestamps
6
+ t.timestamps null: false
7
7
  end
8
8
 
9
9
  class Topic < ActiveRecord::Base
data/test/model/user.rb CHANGED
@@ -5,7 +5,7 @@ ActiveRecord::Base.connection.create_table(:users, :force => true) do |t|
5
5
  t.string :email
6
6
  t.integer :books_count, :default => 0
7
7
  t.integer :images_count, :default => 0
8
- t.timestamps
8
+ t.timestamps null: false
9
9
  end
10
10
 
11
11
  class User < ActiveRecord::Base
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.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-03 00:00:00.000000000 Z
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