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 +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +19 -0
- data/lib/catch_cache/flush.rb +26 -0
- data/lib/catch_cache/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: f1be39350e5522b57dcee53794d5d37ca08ff73c
|
4
|
+
data.tar.gz: dc398cdcc9dbaf81d9fb92d397f531a186356a1e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a82120661973889816be6af945d9a1abc1d93a2d4bd9916f3b556770a43aed72415814a2d12413b1630cd9f73d913ec1a23c27af5a77b42a8beeefa51abce60
|
7
|
+
data.tar.gz: c6e41ce6a058b871298db09ff629ed8d09d12969dfc4bf445ce38ef2b5bf94dc2122afa49894927c2f0c99bb0a78e3d1b395d1c8185e6e5e10ee9026d9710f66
|
data/CHANGELOG.md
CHANGED
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).
|
data/lib/catch_cache/flush.rb
CHANGED
@@ -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
|
data/lib/catch_cache/version.rb
CHANGED
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
|
+
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-
|
11
|
+
date: 2017-09-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|