second_level_cache 2.1.8 → 2.1.9

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eac9a34cfad42e9f20c89eea21bd8f35db5869a9
4
- data.tar.gz: d74fa93c9a2c93b18d5f35de3af34fbe08d29543
3
+ metadata.gz: f6a4e2dad0ed044548798d38f155a9c9f153408e
4
+ data.tar.gz: 4ffb77cc2f17e40d53f3943686f87427c60cd626
5
5
  SHA512:
6
- metadata.gz: 2d278145d9eb185c95150e89e22c9a6cf1e43de72b90d3cd9050db513762a9b5fa4027deb72d1617bd6570417d957c03a06b73cff1725cab90651a4f9486582c
7
- data.tar.gz: 6c9836d37d7a3952b09737f6661941c5c8cc1db606ace0548dc464774daee9a35ec26b0fc8f9324716c0072830b8edd7a5d92bb1f4a05a5777504c4a4b8afdc0
6
+ metadata.gz: 2b60fb3e4e71c77541c568c9b6b29c1840bfe4838b7ef50c7c754b78464ddd41ba2133a80964590d2f259019add8bca1bf5d221d14f6473f3fe69893d27ed92f
7
+ data.tar.gz: de72573534de9d3acd65d5716adfce3e8a26885bd9c94e9808bca70bc371efadbe3c9f46d38c2e0aea6e16d5afbcdb6e9fd9852d47b714e983cdbc491fec4361
data/README.md CHANGED
@@ -1,9 +1,9 @@
1
1
  # SecondLevelCache
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/second_level_cache.png)](http://badge.fury.io/rb/second_level_cache)
4
- [![Dependency Status](https://gemnasium.com/hooopo/second_level_cache.png)](https://gemnasium.com/hooopo/second_level_cache)
5
- [![Build Status](https://travis-ci.org/hooopo/second_level_cache.png?branch=master)](https://travis-ci.org/hooopo/second_level_cache)
6
- [![Code Climate](https://codeclimate.com/github/hooopo/second_level_cache.png)](https://codeclimate.com/github/hooopo/second_level_cache)
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
+ [![Build Status](https://travis-ci.org/hooopo/second_level_cache.svg?branch=master)](https://travis-ci.org/hooopo/second_level_cache)
6
+ [![Code Climate](https://codeclimate.com/github/hooopo/second_level_cache.svg)](https://codeclimate.com/github/hooopo/second_level_cache)
7
7
 
8
8
  SecondLevelCache is a write-through and read-through caching library inspired by Cache Money and cache_fu, support ActiveRecord 4.
9
9
 
@@ -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.8"
20
+ gem "second_level_cache", "~> 2.1.9"
21
21
  ```
22
22
 
23
23
  For ActiveRecord 3:
@@ -91,13 +91,13 @@ ActiveRecord::Base.transaction do
91
91
  user.save
92
92
  account.save
93
93
  Rails.logger.info "info"
94
- end # <- Cache write
94
+ end # <- Cache write
95
95
 
96
96
  # if you want to do something after user and account's write_second_level_cache operation, do this way:
97
97
  ActiveRecord::Base.transaction do
98
98
  user.save
99
99
  account.save
100
- end # <- Cache write
100
+ end # <- Cache write
101
101
  Rails.logger.info "info"
102
102
  ```
103
103
 
@@ -114,7 +114,7 @@ In production env, we recommend to use [Dalli](https://github.com/mperham/dalli)
114
114
  config.cache_store = [:dalli_store, APP_CONFIG["memcached_host"], {:namespace => "ns", :compress => true}]
115
115
  ```
116
116
 
117
- ## Tips:
117
+ ## Tips:
118
118
 
119
119
  * When you want to clear only second level cache apart from other cache for example fragment cache in cache store,
120
120
  you can only change the `cache_key_prefix`:
@@ -130,7 +130,7 @@ class User < ActiveRecord::Base
130
130
  end
131
131
  ```
132
132
 
133
- * It provides a great feature, not hits db when fetching record via unique key(not primary key).
133
+ * It provides a great feature, not hits db when fetching record via unique key(not primary key).
134
134
 
135
135
  ```ruby
136
136
  # this will fetch from cache
@@ -12,8 +12,8 @@ module SecondLevelCache
12
12
 
13
13
  def find_target_with_second_level_cache
14
14
  return find_target_without_second_level_cache unless klass.second_level_cache_enabled?
15
- return find_target_without_second_level_cache if reflection.options[:through]
16
- # TODO: implement cache with has_one through
15
+ return find_target_without_second_level_cache if reflection.options[:through] || reflection.scope
16
+ # TODO: implement cache with has_one through, scope
17
17
  if reflection.options[:as]
18
18
  cache_record = klass.fetch_by_uniq_keys({reflection.foreign_key => owner[reflection.active_record_primary_key], reflection.type => owner.class.base_class.name})
19
19
  else
@@ -1,4 +1,4 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  module SecondLevelCache
3
- VERSION = "2.1.8"
3
+ VERSION = "2.1.9"
4
4
  end
@@ -24,4 +24,14 @@ class HasOneAssociationTest < ActiveSupport::TestCase
24
24
  # clean_user.forked_from_user
25
25
  # end
26
26
  end
27
+
28
+ def test_has_one_with_conditions
29
+ user = User.create name: 'hooopo', email: 'hoooopo@gmail.com'
30
+ group_namespace1 = Namespace.create(user_id: user.id, name: 'ruby-china', kind: 'group')
31
+ user.create_namespace(name: 'hooopo')
32
+ group_namespace2 = Namespace.create(user_id: user.id, name: 'rails', kind: 'group')
33
+ assert_not_equal user.namespace, nil
34
+ clear_user = User.find(user.id)
35
+ assert_equal clear_user.namespace.name, 'hooopo'
36
+ end
27
37
  end
data/test/model/user.rb CHANGED
@@ -15,6 +15,13 @@ ActiveRecord::Base.connection.create_table(:forked_user_links, :force => true) d
15
15
  t.timestamps null: false
16
16
  end
17
17
 
18
+ ActiveRecord::Base.connection.create_table(:namespaces, :force => true) do |t|
19
+ t.integer :user_id
20
+ t.string :kind
21
+ t.string :name
22
+ t.timestamps null: false
23
+ end
24
+
18
25
  class User < ActiveRecord::Base
19
26
  CacheVersion = 3
20
27
  serialize :options, Array
@@ -25,10 +32,18 @@ class User < ActiveRecord::Base
25
32
  has_one :account
26
33
  has_one :forked_user_link, foreign_key: 'forked_to_user_id'
27
34
  has_one :forked_from_user, through: :forked_user_link
35
+ has_many :namespaces
36
+ has_one :namespace, -> { where(kind: nil) }
28
37
  has_many :books
29
38
  has_many :images, :as => :imagable
30
39
  end
31
40
 
41
+ class Namespace < ActiveRecord::Base
42
+ acts_as_cached(:version => 1, :expires_in => 3.day)
43
+
44
+ belongs_to :user
45
+ end
46
+
32
47
  class ForkedUserLink < ActiveRecord::Base
33
48
  belongs_to :forked_from_user, class_name: User
34
49
  belongs_to :forked_to_user, class_name: User
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.8
4
+ version: 2.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hooopo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-14 00:00:00.000000000 Z
11
+ date: 2016-02-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport