second_level_cache 2.4.3 → 2.4.4

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
- SHA256:
3
- metadata.gz: 3ff0808eae35d2e443ca1160f93eaa9f23f9b1267e4338d3d89fca45715d0fbf
4
- data.tar.gz: 1daad06b799d5506b2dff7cb23c898af371612cb38cc8963d24ea9276c66b30b
2
+ SHA1:
3
+ metadata.gz: 53372ad4a8c4950dde0b32e9307ae5a104f23bc6
4
+ data.tar.gz: 13065046314c304e6409c93fe7a10e92d597cece
5
5
  SHA512:
6
- metadata.gz: 564bd8a1dfeebb096450334bca5c077df923ffc6120e72d025188c1d47b8a705e003ff24f0698b59b0b60d32c877a90cb158286299c0683142bbe6612b31416d
7
- data.tar.gz: efaf40b630af426f52538468c96b6d7ea24e14ed4137c3fedccadcc8de7c2c9c82c86b6ccf48d98a7c712e8d470ad997cb902199412f517ed5ebfa0187538cbe
6
+ metadata.gz: 422b464203cc111ad3ffa58fe36116ae4438988a0e0630f361bdec6db9c2b614feeb1b4d713b4b211c2b9646dfaf61ec673d7d5107189bdd582de12240691b48
7
+ data.tar.gz: eaae2b651b0746200f05567a65450a1326ce4496d3120872de7b75b7d352011252236f1504ae03383922cc7bd477429a9252c60174f8724cecfc492f43035828
data/README.md CHANGED
@@ -1,7 +1,6 @@
1
1
  # SecondLevelCache
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/second_level_cache.svg)](http://badge.fury.io/rb/second_level_cache)
4
- [![Dependency Status](https://gemnasium.com/hooopo/second_level_cache.svg)](https://gemnasium.com/hooopo/second_level_cache)
5
4
  [![Build Status](https://travis-ci.org/hooopo/second_level_cache.svg?branch=master)](https://travis-ci.org/hooopo/second_level_cache)
6
5
  [![Code Climate](https://codeclimate.com/github/hooopo/second_level_cache.svg)](https://codeclimate.com/github/hooopo/second_level_cache)
7
6
 
@@ -11,6 +11,24 @@ module SecondLevelCache
11
11
  block_given? ? yield(Config) : Config
12
12
  end
13
13
 
14
+ def self.without_second_level_cache
15
+ old_cache_enabled = SecondLevelCache.cache_enabled?
16
+ SecondLevelCache.cache_enabled = false
17
+
18
+ yield
19
+ ensure
20
+ SecondLevelCache.cache_enabled = old_cache_enabled
21
+ end
22
+
23
+ def self.cache_enabled?
24
+ cache_enabled = Thread.current[:slc_cache_enabled]
25
+ cache_enabled.nil? ? true : cache_enabled
26
+ end
27
+
28
+ def self.cache_enabled=(cache_enabled)
29
+ Thread.current[:slc_cache_enabled] = cache_enabled
30
+ end
31
+
14
32
  class << self
15
33
  delegate :logger, :cache_store, :cache_key_prefix, to: Config
16
34
  end
@@ -56,7 +56,7 @@ module SecondLevelCache
56
56
  end
57
57
 
58
58
  record = super(limit)
59
- record&.write_second_level_cache
59
+ record&.write_second_level_cache if select_all_column?
60
60
  record
61
61
  end
62
62
 
@@ -20,19 +20,14 @@ module SecondLevelCache
20
20
 
21
21
  def second_level_cache_enabled?
22
22
  if defined? @second_level_cache_enabled
23
- @second_level_cache_enabled == true
23
+ @second_level_cache_enabled == true && SecondLevelCache.cache_enabled?
24
24
  else
25
25
  false
26
26
  end
27
27
  end
28
28
 
29
- def without_second_level_cache
30
- old = @second_level_cache_enabled
31
- @second_level_cache_enabled = false
32
-
33
- yield if block_given?
34
- ensure
35
- @second_level_cache_enabled = old
29
+ def without_second_level_cache(&blk)
30
+ SecondLevelCache.without_second_level_cache(&blk) if blk
36
31
  end
37
32
 
38
33
  # Get MD5 digest of this Model schema
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SecondLevelCache
4
- VERSION = "2.4.3"
4
+ VERSION = "2.4.4"
5
5
  end
@@ -33,7 +33,7 @@ Gem::Specification.new do |gem|
33
33
  gem.add_runtime_dependency 'activesupport', ['>= 5.2.0.rc', '< 6']
34
34
  gem.add_runtime_dependency 'activerecord', ['>= 5.2.0.rc', '< 6']
35
35
 
36
- gem.add_development_dependency 'sqlite3'
36
+ gem.add_development_dependency 'sqlite3', '< 1.4'
37
37
  gem.add_development_dependency 'rake'
38
38
  gem.add_development_dependency 'pry'
39
39
  gem.add_development_dependency 'database_cleaner'
@@ -42,6 +42,11 @@ class FetchByUinqKeyTest < ActiveSupport::TestCase
42
42
  end
43
43
  end
44
44
 
45
+ def test_should_return_nil_when_record_not_found
46
+ assert_not_nil Post.fetch_by_uniq_keys(topic_id: 2, slug: "foobar")
47
+ assert_nil Post.fetch_by_uniq_keys(topic_id: 3, slug: "foobar")
48
+ end
49
+
45
50
  def test_should_work_with_fetch_by_uniq_key
46
51
  user = User.fetch_by_uniq_key(@user.name, :name)
47
52
  assert_equal user, @user
@@ -72,4 +72,10 @@ class FinderMethodsTest < ActiveSupport::TestCase
72
72
  assert_equal @user, User.unscoped.where(id: @user.id).last
73
73
  end
74
74
  end
75
+
76
+ def test_should_not_write_cache_for_first
77
+ @user = User.select("id").first
78
+ @user = User.find(@user.id)
79
+ assert_equal "csdn", @user.name
80
+ end
75
81
  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.4.3
4
+ version: 2.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hooopo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-14 00:00:00.000000000 Z
11
+ date: 2019-07-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -54,16 +54,16 @@ dependencies:
54
54
  name: sqlite3
55
55
  requirement: !ruby/object:Gem::Requirement
56
56
  requirements:
57
- - - ">="
57
+ - - "<"
58
58
  - !ruby/object:Gem::Version
59
- version: '0'
59
+ version: '1.4'
60
60
  type: :development
61
61
  prerelease: false
62
62
  version_requirements: !ruby/object:Gem::Requirement
63
63
  requirements:
64
- - - ">="
64
+ - - "<"
65
65
  - !ruby/object:Gem::Version
66
- version: '0'
66
+ version: '1.4'
67
67
  - !ruby/object:Gem::Dependency
68
68
  name: rake
69
69
  requirement: !ruby/object:Gem::Requirement
@@ -192,7 +192,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
192
192
  version: '0'
193
193
  requirements: []
194
194
  rubyforge_project:
195
- rubygems_version: 2.7.6
195
+ rubygems_version: 2.5.2.3
196
196
  signing_key:
197
197
  specification_version: 4
198
198
  summary: 'SecondLevelCache is a write-through and read-through caching library inspired