cache_associations 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/cache_associations.rb +2 -0
- data/lib/cache_associations/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f3c9a712f9405d1416e18af9ce780fac80f199f
|
4
|
+
data.tar.gz: 3e9ce36be672bb9d7334130b474bfe3a9413a482
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec1a1351dd9fc79dc788b0af27e1a49044a08e24d7897cf9b2b773592139d24d0401385b5c2db6a57702a6098a404c58ec1799b1e5cf136865aae198a191b228
|
7
|
+
data.tar.gz: 7229a72a7c0eae3f476f36a1279103dc242a4120322e87ee6a1b24df2b315a95028dbb9871a8b5e419a6a09947fef1e1617329d037401748e2b8ce5b191e582e
|
data/README.md
CHANGED
@@ -39,7 +39,7 @@ class User < ApplicationRecord
|
|
39
39
|
|
40
40
|
# you do not need to provide a block to specify the cache
|
41
41
|
# name, this will provide you a default name composed of
|
42
|
-
# [
|
42
|
+
# [reflection.klass.name, send(reflection.foreign_key)]
|
43
43
|
cache_global_association :profile
|
44
44
|
|
45
45
|
def factorial_1000
|
@@ -73,7 +73,7 @@ irb> u.clear_caching_on_association(:profile) # clear the cache
|
|
73
73
|
You may customize what the data you cached, the cached method accepts an optional block that determines how to cache data.
|
74
74
|
But it will break the original association, so you should be careful with this feature.
|
75
75
|
|
76
|
-
```
|
76
|
+
```ruby
|
77
77
|
irb> u = User.take
|
78
78
|
irb> u.cached_profile do "gotcha" end
|
79
79
|
=> "gotcha"
|
data/lib/cache_associations.rb
CHANGED
@@ -19,6 +19,8 @@ module CacheAssociations
|
|
19
19
|
options = Rails.cache.options.merge(options)
|
20
20
|
|
21
21
|
define_method("cached_#{name}") do |*args, &block|
|
22
|
+
break send(name) unless association_instance_get(name).nil?
|
23
|
+
|
22
24
|
cache_name = cache_name_block.nil? ? default_cache_name(name) : instance_exec(&cache_name_block)
|
23
25
|
cache = Rails.cache.fetch(cache_name, **options) do
|
24
26
|
break instance_exec(*args, &block) if !block.nil?
|
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.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fuxin Hao
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-08-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|