catch_cache 0.0.1 → 0.0.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: c7483e2c5ebc02ca6b215f6f590c5d5f78736da9
4
- data.tar.gz: 51474f2be2b8fdbc0ba165891df25f9d04c5aa7c
3
+ metadata.gz: 662566bebd0e5976fabadbd420e8232dc6d59fb1
4
+ data.tar.gz: d41e1ac4a87b44583b1600d3626785847bfe3c27
5
5
  SHA512:
6
- metadata.gz: 20cee8a984c72adf837c9b74e43438835e7239094c1d8270d4a7aa1eb449b532dc2a9bcf8d7aac5112a47eaf3f30657bed7415cd9974e435e11964a9a079a78d
7
- data.tar.gz: 0b04dbcf1b82be6b776f571788bf9d4bda5b119d7793f36a88d4784eedb781dd7d253fbbf317dea481cc6fef77e9457397a5ccb28789e736e1e2a914ac0c2b97
6
+ metadata.gz: 8adfa928da3c75f48c3f59d22fecf7c9f3efe369d3446a5c9c7c4974b8264a0166b917c1e61ab827db9a696b16ef7dee856ff5e3f618491047dfa009226f19ef
7
+ data.tar.gz: 192116052ba1636f97f6fccb46044c376cf9edaba122e95f7be1f49e13edf8dbecf080a624e1fe74f801f8785392478893786e52d279c8029db99cd71d8c1590
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ # 0.0.2
2
+
3
+ - Swallow errors when calling the `key_callbacks` proc in `:flush_cache!`
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # CatchCache
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/catch_cache`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ An easy way to manage caching and flushing of Ruby objects. Especially useful when you are speeding a very slow API or page.
6
4
 
7
5
  ## Installation
8
6
 
@@ -22,17 +20,36 @@ Or install it yourself as:
22
20
 
23
21
  ## Usage
24
22
 
25
- TODO: Write usage instructions here
23
+ ```ruby
24
+ class ServiceWithAVerySlowQuery
25
+ include CatchCache::Cache
26
+
27
+ def query
28
+ lead = get_some_lead
29
+ catch_then_cache("lead_timeline_logs_#{lead.id}") do
30
+ # Your very slow query which
31
+ # returns a bunch of Ruby objects
32
+ end
33
+ end
34
+ end
35
+ ```
26
36
 
27
- ## Development
37
+ In your AR model:
28
38
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
39
+ ```ruby
40
+ In your AR model:
30
41
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
42
+ class LoanApplication < ActiveRecord::Base
43
+ include CatchCache::Flush
32
44
 
33
- ## Contributing
45
+ belongs_to :lead
34
46
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/catch_cache.
47
+ # Everytime the :after_commit AR callback is called,
48
+ # the Redis cache with id "lead_timeline_logs_#{lead.id}"
49
+ # is going to be flushed
50
+ cache_id :lead_timeline_logs, -> { lead.id }
51
+ end
52
+ ```
36
53
 
37
54
  ## License
38
55
 
@@ -9,14 +9,18 @@ module CatchCache
9
9
  define_method(:flush_cache!) do
10
10
  key_callbacks = ClassMethods.key_callbacks
11
11
 
12
- key_callbacks.keys.each do |key|
13
- # Get the uniq id defined in the AR model
14
- uniq_id = instance_exec(&key_callbacks[key])
15
- # Build the redis cache key
16
- cache_key = "#{key.to_s}_#{uniq_id}"
17
- redis = Redis.new
18
- # Flush the key by setting it to nil
19
- redis.set(cache_key, nil)
12
+ begin
13
+ key_callbacks.keys.each do |key|
14
+ # Get the uniq id defined in the AR model
15
+ uniq_id = instance_exec(&key_callbacks[key])
16
+ # Build the redis cache key
17
+ cache_key = "#{key.to_s}_#{uniq_id}"
18
+ redis = Redis.new
19
+ # Flush the key by setting it to nil
20
+ redis.set(cache_key, nil)
21
+ end
22
+ rescue NameError => e
23
+ # Nothing was flushed because of an error"
20
24
  end
21
25
  end
22
26
 
@@ -1,3 +1,3 @@
1
1
  module CatchCache
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: catch_cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Neil Marion dela Cruz
@@ -76,6 +76,7 @@ files:
76
76
  - ".gitignore"
77
77
  - ".rspec"
78
78
  - ".travis.yml"
79
+ - CHANGELOG.md
79
80
  - Gemfile
80
81
  - LICENSE.txt
81
82
  - README.md