cacheflow 0.1.0 → 0.1.1

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: ed9289534d7be914a8031cf433b80a715f09c20d
4
- data.tar.gz: 5790af33bcd0fd95b166d1426756ece322f305e0
3
+ metadata.gz: ac0a2640873e62e3bbb8770586da459cc7de3657
4
+ data.tar.gz: 5359925b29dd20b4006c44c214ab5313b2114313
5
5
  SHA512:
6
- metadata.gz: c19673a2d24c9fa317035753b31f85ec1e69efb6a62a960344b08385f7a576c0d29f136760499989c2a0852c0bfbd6edfd0daf3210dbd14f167bcdd17ab1515f
7
- data.tar.gz: 176fe8f019a0328916ca81921725d17d1a2e5578fe0cb11523e4e4fe3a50fd3fb8106b5668a6f6ef26c41691351e376a187929f6e59823194c5ad96f10eff5d6
6
+ metadata.gz: 6148305fbd5825dd61031e813b080c105076b45ab341b12a7fa908f440d9e4125d457ea2ee4039cd02614dcb99fa8fee967e920c5a34c0192389afb9fe49bfd6
7
+ data.tar.gz: c3382fb7dc4f4c125ecc9c1d3e234060103d316540fb968a32e35b9a5d76e36ab84ba181fc509f216feb6ffad92944c4677aece4a9769f4a3fbbf71b9555ce99
@@ -1,3 +1,8 @@
1
+ ## 0.1.1
2
+
3
+ - Added `silence` method
4
+ - Added `silence_sidekiq!` method
5
+
1
6
  ## 0.1.0
2
7
 
3
8
  - First release
data/README.md CHANGED
@@ -11,11 +11,27 @@ Works with the Rails cache, as well as [Dalli](https://github.com/petergoldstein
11
11
  Add this line to your application’s Gemfile:
12
12
 
13
13
  ```ruby
14
- gem 'cacheflow'
14
+ gem 'cacheflow', group: :development
15
15
  ```
16
16
 
17
17
  When your log level is set to `DEBUG` (Rails default in development), all commands to Memcached and Redis are logged.
18
18
 
19
+ ## Features
20
+
21
+ To silence logging, use:
22
+
23
+ ```ruby
24
+ Cacheflow.silence do
25
+ # code
26
+ end
27
+ ```
28
+
29
+ To silence logging for only [Sidekiq](https://github.com/mperham/sidekiq) commands, create an initializer with:
30
+
31
+ ```ruby
32
+ Cacheflow.silence_sidekiq!
33
+ ```
34
+
19
35
  ## History
20
36
 
21
37
  View the [changelog](https://github.com/ankane/cacheflow/blob/master/CHANGELOG.md)
@@ -6,6 +6,45 @@ module Cacheflow
6
6
  require "cacheflow/memcached" if defined?(Dalli)
7
7
  require "cacheflow/redis" if defined?(Redis)
8
8
  end
9
+
10
+ def self.silenced?
11
+ Thread.current[:cacheflow_silenced]
12
+ end
13
+
14
+ def self.silence
15
+ previous_value = silenced?
16
+ begin
17
+ Thread.current[:cacheflow_silenced] = true
18
+ yield
19
+ ensure
20
+ Thread.current[:cacheflow_silenced] = previous_value
21
+ end
22
+ end
23
+
24
+ def self.silence_sidekiq!
25
+ ::Sidekiq.singleton_class.prepend(Cacheflow::Sidekiq::ClassMethods)
26
+ ::Sidekiq::Client.prepend(Cacheflow::Sidekiq::Client::InstanceMethods)
27
+ end
28
+
29
+ module Sidekiq
30
+ module ClassMethods
31
+ def redis(*_)
32
+ Cacheflow.silence do
33
+ super
34
+ end
35
+ end
36
+ end
37
+
38
+ module Client
39
+ module InstanceMethods
40
+ def push(*_)
41
+ Cacheflow.silence do
42
+ super
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
9
48
  end
10
49
 
11
50
  if defined?(Rails)
@@ -14,7 +14,7 @@ module Cacheflow
14
14
 
15
15
  class Instrumenter < ActiveSupport::LogSubscriber
16
16
  def query(event)
17
- return unless logger.debug?
17
+ return if !logger.debug? || Cacheflow.silenced?
18
18
 
19
19
  name = "%s (%.2fms)" % ["Memcached", event.duration]
20
20
  debug " #{color(name, BLUE, true)} #{event.payload[:op].to_s.upcase} #{event.payload[:args].join(" ")}"
@@ -13,7 +13,7 @@ module Cacheflow
13
13
 
14
14
  class Instrumenter < ActiveSupport::LogSubscriber
15
15
  def query(event)
16
- return unless logger.debug?
16
+ return if !logger.debug? || Cacheflow.silenced?
17
17
 
18
18
  name = "%s (%.2fms)" % ["Redis", event.duration]
19
19
 
@@ -1,3 +1,3 @@
1
1
  module Cacheflow
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cacheflow
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-09-30 00:00:00.000000000 Z
11
+ date: 2017-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport