catch_cache 0.0.5 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +11 -14
- data/lib/catch_cache/flush.rb +4 -4
- 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: 260cf4536507513b4873a3f6e4abc651e6928b60
|
4
|
+
data.tar.gz: 9381ed6c9bc99673011bd8414afd31bebf5ee45f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0dac7694d9ccb255df40521f22e57ab811184f3bdea6b4f6539f533169e40ffb07563e0ab47c8e4eebee2def3a1f8d99b2545dcabc03d0d57807afd38fa543c6
|
7
|
+
data.tar.gz: 4706a9e68beb6609c714b30c12122f0e706f57b04a4ec81e4033577869245b4e5fb3439c2689db04862eb0dc9aba0f51804f7debf20dabfff31c6b46c2c454a1
|
data/CHANGELOG.md
CHANGED
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
|
-
|
48
|
+
|
49
|
+
cache_id :lead_timeline_logs, after_commit: -> { lead.id }
|
51
50
|
end
|
52
51
|
```
|
53
52
|
|
54
|
-
|
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
|
59
|
+
class AdminUser < ActiveRecord::Base
|
58
60
|
include CatchCache::Flush
|
59
61
|
|
60
|
-
|
61
|
-
|
62
|
-
|
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
|
data/lib/catch_cache/flush.rb
CHANGED
@@ -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
|
-
|
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
|
|
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.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-
|
11
|
+
date: 2017-09-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|