cache_associations 0.1.1 → 0.1.2

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: 0990e10af89e0c1b3e90b5679ff9ced7a8afcdd9
4
- data.tar.gz: 848feee285e44e564ef53c0ca97b0c52a75abb04
3
+ metadata.gz: 25c9f69129b50855b9f24bd5d22e9b1cbc3a2258
4
+ data.tar.gz: 383ec8b76bfe25a25bae015bb690c55b450fc4eb
5
5
  SHA512:
6
- metadata.gz: 38c0a5abaa5176976e17633127ad9b1fed5a94052d033ee73b5c2628120115d1f3241799b714102f1e066b3642ed000d0af60db7685aa443301c82ca7857190b
7
- data.tar.gz: eaad8c3f149c6595fe79be5dc93658102dcfa77cb660c428ebb171e921cb024b430b975e6495bde9cae0bc8e92dd6d1d2fbeb04dff9f7e0624e77a7dc835e556
6
+ metadata.gz: e19b8231d349d5d6560fd2229474db3981909acabcaab381b6f736aaedec8a546467b1bf6979001d172258ec3210808ad45c3740c4861780936074ec45d5df62
7
+ data.tar.gz: df928e1a5a1a2f9265db2177282bd9587fd70576fec7dfa43cb1fb067efc0ae9823af0028eb3f83012416503e5dba94d1606129514cdb6ce2d0127c274672bfc
data/README.md CHANGED
@@ -40,6 +40,8 @@ end
40
40
  ```
41
41
 
42
42
  The `cache_association` defines a method `cached_profile` to fetch data from the cache store.
43
+ You may also specify additional options via the options argument, it's the same as `ActiveSupport::Cache::Store#fetch`,
44
+ such as setting `:expires_in` will set an expiration time on the cache.
43
45
  And `cache_association` accepts an optional block to define the cache name, it's `[self.class.name, id, name, updated_at.to_i]` in default.
44
46
 
45
47
  ```ruby
@@ -6,14 +6,15 @@ module CacheAssociations
6
6
  UndefinedAssociationError = Class.new(StandardError)
7
7
 
8
8
  class_methods do
9
- def cache_association(name, &cache_name_block)
9
+ def cache_association(name, **options, &cache_name_block)
10
10
  unless reflection = reflect_on_association(name)
11
11
  raise UndefinedAssociationError, "Undefined asscociation #{name}"
12
12
  end
13
+ options = Rails.cache.options.merge(options)
13
14
 
14
15
  define_method("cached_#{name}") do |*args, &block|
15
16
  cache_name = cache_name_block.nil? ? [self.class.name, id, name, updated_at.to_i] : instance_exec(&cache_name_block)
16
- cache = Rails.cache.fetch(cache_name) do
17
+ cache = Rails.cache.fetch(cache_name, **options) do
17
18
  break instance_exec(*args, &block) if !block.nil?
18
19
 
19
20
  if reflection.collection?
@@ -1,3 +1,3 @@
1
1
  module CacheAssociations
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cache_associations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fuxin Hao