catch_cache 0.0.4 → 0.0.5

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: f429e2d8e44cc52686cc770cc9c77e2f2d177555
4
- data.tar.gz: d6991666b892385092998cd57b9df36f094aaa56
3
+ metadata.gz: f1be39350e5522b57dcee53794d5d37ca08ff73c
4
+ data.tar.gz: dc398cdcc9dbaf81d9fb92d397f531a186356a1e
5
5
  SHA512:
6
- metadata.gz: c9fc6fa5f4e6b6dadf079e991114d3d57dcb9e8e39fa0863102da6e09432c3005b8832db783c70de5b75e4018abd64e7185fe71722d9339e6302649e6468e4f4
7
- data.tar.gz: d5b7c095a51dff602d1a4b4e972885e095501e453cd4e022c7cd9684f77b71f1a5f7979029f8446f0b8b4926e546deb38b872a352427d406fc78dabde5ec76b0
6
+ metadata.gz: 6a82120661973889816be6af945d9a1abc1d93a2d4bd9916f3b556770a43aed72415814a2d12413b1630cd9f73d913ec1a23c27af5a77b42a8beeefa51abce60
7
+ data.tar.gz: c6e41ce6a058b871298db09ff629ed8d09d12969dfc4bf445ce38ef2b5bf94dc2122afa49894927c2f0c99bb0a78e3d1b395d1c8185e6e5e10ee9026d9710f66
@@ -1,3 +1,7 @@
1
+ # 0.0.5
2
+
3
+ - Add callback support, like `after_commit: :flush_all!`
4
+
1
5
  # 0.0.4
2
6
 
3
7
  - Fix catching of errors in `#flush_cache!`
data/README.md CHANGED
@@ -51,6 +51,25 @@ class LoanApplication < ActiveRecord::Base
51
51
  end
52
52
  ```
53
53
 
54
+ You could also register callbacks using `cache_id`
55
+
56
+ ```ruby
57
+ class LoanApplication < ActiveRecord::Base
58
+ include CatchCache::Flush
59
+
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`
68
+
69
+ ```ruby
70
+ cache_id :lead_timeline_logs, after_commit: :flush_all!
71
+ ```
72
+
54
73
  ## License
55
74
 
56
75
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -24,6 +24,16 @@ module CatchCache
24
24
  end
25
25
  end
26
26
 
27
+ define_method(:flush_all!) do
28
+ redis = Redis.new
29
+
30
+ registered_keys = ClassMethods.key_callbacks.keys
31
+ removable_keys = redis.keys.select do |key|
32
+ registered_keys.include?(key.gsub(/\_[0-9]+/, '').to_sym)
33
+ end
34
+
35
+ redis.del(removable_keys) if removable_keys.present?
36
+ end
27
37
  end
28
38
  end
29
39
 
@@ -42,7 +52,23 @@ module CatchCache
42
52
  # An example of a redis key is
43
53
  # "lead_logs_cache_<uniq_id>"
44
54
  def cache_id(*args)
55
+ options = args.last if args.last.is_a?(Hash)
56
+
45
57
  key_callbacks[args.first] = args.second
58
+ register_callbacks_for(options) if options.present?
59
+ end
60
+
61
+ private
62
+
63
+ def register_callbacks_for(options)
64
+ options.each do |callback, callable|
65
+ case callback
66
+ when Symbol
67
+ send(callback, callable) if respond_to?(callback)
68
+ else # It must be Proc or lambda
69
+ send(callback, &callable)
70
+ end
71
+ end
46
72
  end
47
73
  end
48
74
  end
@@ -1,3 +1,3 @@
1
1
  module CatchCache
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
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.4
4
+ version: 0.0.5
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-08-14 00:00:00.000000000 Z
11
+ date: 2017-09-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis