cache_associations 0.2.2 → 0.3

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: d7f050b7803ddbc885d61d99b9b8185a2634d99e
4
- data.tar.gz: 6f01159113698d2988abca4ac7153ad698afbc38
3
+ metadata.gz: 32b28bb91ce8272843abdf8a1bad4a378d7ef6c6
4
+ data.tar.gz: f604864414fa453b35bb0427d845eddb26cdbdaa
5
5
  SHA512:
6
- metadata.gz: 699b8e137706a28e48fd29117ceeef3b1de2aab33d366cc8db3c732e77ca187e282a71b99880447fbb09557aa3134ad1e583b53d88faccccaae9f754afb870bb
7
- data.tar.gz: 77c42a9c2f6c97c67f19016b285403dfadee8938acb72012f1aa7ef6002408554a3db8c1ac382c0084477da17bd1c9a5ca2aac5f68bde312b5a47d89c4988adc
6
+ metadata.gz: 24dee2057a4960ea396a6c1bb22b56e37deb8343e67701b21d67a868d391e4ce2aef3d691b1642258061c44bf149156f3bb9103ef4533543388bf1e5d8e59c18
7
+ data.tar.gz: 2fee5df99f3fffcb8620f1aed261430284533f7def49cb6920a6340dd36dc3a71a77cdd694ca8ca2e6b654402febb81d96c1f81e269d5d5e0bd4973b5af9d900
data/README.md CHANGED
@@ -29,10 +29,19 @@ class User < ApplicationRecord
29
29
 
30
30
  has_one :profile
31
31
  cache_association :profile do
32
- # put your cache name here
32
+ # Put your cache name here
33
+ #
34
+ # This is the default naming convention,
35
+ # so if you follow the naming strategy,
36
+ # you are free with providing the block
33
37
  [self.class.name, id, 'profile', update_at.to_i]
34
38
  end
35
39
 
40
+ # you do not need to provide a block to specify the cache
41
+ # name, this will provide you a default name composed of
42
+ # [self.class.reflect_on_association(name).klass.name, id]
43
+ cache_global_association :profile
44
+
36
45
  def factorial_1000
37
46
  (1..1000).inject(:*)
38
47
  end
@@ -10,6 +10,11 @@ module CacheAssociations
10
10
  unless reflection = reflect_on_association(name)
11
11
  raise UndefinedAssociationError, "Undefined asscociation #{name}"
12
12
  end
13
+
14
+ unless block_given?
15
+ cache_name_block = lambda { [self.class.name, id, name, updated_at.to_i] }
16
+ end
17
+
13
18
  register_cache_name_block(name, cache_name_block)
14
19
  options = Rails.cache.options.merge(options)
15
20
 
@@ -34,6 +39,16 @@ module CacheAssociations
34
39
  cache
35
40
  end
36
41
  end
42
+
43
+ def cache_global_association(name, global_key = nil, **options)
44
+ if global_key.blank?
45
+ cache_name_block = lambda { [self.class.reflect_on_association(name).klass.name, id] }
46
+ else
47
+ cache_name_block = lambda { global_key }
48
+ end
49
+
50
+ cache_association(name, **options, &cache_name_block)
51
+ end
37
52
 
38
53
  def cache_method(name, **options, &cache_name_block)
39
54
  register_cache_name_block(name, cache_name_block)
@@ -1,3 +1,3 @@
1
1
  module CacheAssociations
2
- VERSION = "0.2.2"
2
+ VERSION = "0.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cache_associations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: '0.3'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fuxin Hao
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-11-27 00:00:00.000000000 Z
11
+ date: 2018-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -105,7 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
105
  version: '0'
106
106
  requirements: []
107
107
  rubyforge_project:
108
- rubygems_version: 2.5.1
108
+ rubygems_version: 2.6.11
109
109
  signing_key:
110
110
  specification_version: 4
111
111
  summary: To make Low-Level caching collaborate with Association caching.