catch_cache 0.0.5 → 0.1.0

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: f1be39350e5522b57dcee53794d5d37ca08ff73c
4
- data.tar.gz: dc398cdcc9dbaf81d9fb92d397f531a186356a1e
3
+ metadata.gz: 260cf4536507513b4873a3f6e4abc651e6928b60
4
+ data.tar.gz: 9381ed6c9bc99673011bd8414afd31bebf5ee45f
5
5
  SHA512:
6
- metadata.gz: 6a82120661973889816be6af945d9a1abc1d93a2d4bd9916f3b556770a43aed72415814a2d12413b1630cd9f73d913ec1a23c27af5a77b42a8beeefa51abce60
7
- data.tar.gz: c6e41ce6a058b871298db09ff629ed8d09d12969dfc4bf445ce38ef2b5bf94dc2122afa49894927c2f0c99bb0a78e3d1b395d1c8185e6e5e10ee9026d9710f66
6
+ metadata.gz: 0dac7694d9ccb255df40521f22e57ab811184f3bdea6b4f6539f533169e40ffb07563e0ab47c8e4eebee2def3a1f8d99b2545dcabc03d0d57807afd38fa543c6
7
+ data.tar.gz: 4706a9e68beb6609c714b30c12122f0e706f57b04a4ec81e4033577869245b4e5fb3439c2689db04862eb0dc9aba0f51804f7debf20dabfff31c6b46c2c454a1
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ # 0.1.0
2
+
3
+ - Update usage
4
+ - Fix issue where `:flush_cache` is being defined as an `:after_commit` callback no matter what
5
+ - Fix storing and access of key callbacks procs
6
+
1
7
  # 0.0.5
2
8
 
3
9
  - Add callback support, like `after_commit: :flush_all!`
data/README.md CHANGED
@@ -37,8 +37,6 @@ end
37
37
  In your AR model:
38
38
 
39
39
  ```ruby
40
- In your AR model:
41
-
42
40
  class LoanApplication < ActiveRecord::Base
43
41
  include CatchCache::Flush
44
42
 
@@ -47,27 +45,26 @@ class LoanApplication < ActiveRecord::Base
47
45
  # Everytime the :after_commit AR callback is called,
48
46
  # the Redis cache with id "lead_timeline_logs_#{lead.id}"
49
47
  # is going to be flushed
50
- cache_id :lead_timeline_logs, -> { lead.id }
48
+
49
+ cache_id :lead_timeline_logs, after_commit: -> { lead.id }
51
50
  end
52
51
  ```
53
52
 
54
- You could also register callbacks using `cache_id`
53
+ ### :flush_all!
54
+ Use `:flush_all` to clear the cache for all the keys with the suffix defined in `cache_id`
55
+
56
+ In your AR model:
55
57
 
56
58
  ```ruby
57
- class LoanApplication < ActiveRecord::Base
59
+ class AdminUser < ActiveRecord::Base
58
60
  include CatchCache::Flush
59
61
 
60
- cache_id :lead_timeline_logs, after_commit: :do_something_with_cache
61
- cache_id :central_page_loan_plans, after_commit: -> { do_something_with_cache }
62
- end
63
- ```
64
-
65
- ## API
66
- - ### flush_all!
67
- Clears cache for all the keys registered with `cache_id`
62
+ # Everytime the :after_commit AR callback is called,
63
+ # all the Redis caches with suffix "lead_timeline_logs"
64
+ # are going to be flushed
68
65
 
69
- ```ruby
70
66
  cache_id :lead_timeline_logs, after_commit: :flush_all!
67
+ end
71
68
  ```
72
69
 
73
70
  ## License
@@ -4,17 +4,17 @@ module CatchCache
4
4
  def included(klass)
5
5
  klass.class_eval do
6
6
  extend ClassMethods
7
- after_commit :flush_cache!
8
7
 
9
8
  define_method(:flush_cache!) do
10
9
  key_callbacks = ClassMethods.key_callbacks
11
10
 
12
- key_callbacks.keys.each do |key|
11
+
12
+ key_callbacks.keys.select{|key| key.to_s.split("__").last == self.class.name.underscore }.each do |key|
13
13
  # Get the uniq id defined in the AR model
14
14
  begin
15
15
  uniq_id = instance_exec(&key_callbacks[key])
16
16
  # Build the redis cache key
17
- cache_key = "#{key.to_s}_#{uniq_id}"
17
+ cache_key = "#{key.to_s.split("__").first}_#{uniq_id}"
18
18
  redis = Redis.new
19
19
  # Flush the key by setting it to nil
20
20
  redis.set(cache_key, nil)
@@ -54,7 +54,7 @@ module CatchCache
54
54
  def cache_id(*args)
55
55
  options = args.last if args.last.is_a?(Hash)
56
56
 
57
- key_callbacks[args.first] = args.second
57
+ key_callbacks["#{args.first}__#{self.name.underscore}".to_sym] = args.second
58
58
  register_callbacks_for(options) if options.present?
59
59
  end
60
60
 
@@ -1,3 +1,3 @@
1
1
  module CatchCache
2
- VERSION = "0.0.5"
2
+ VERSION = "0.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: catch_cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Neil Marion dela Cruz
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-09-12 00:00:00.000000000 Z
11
+ date: 2017-09-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis