cacheflow 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ed9289534d7be914a8031cf433b80a715f09c20d
4
+ data.tar.gz: 5790af33bcd0fd95b166d1426756ece322f305e0
5
+ SHA512:
6
+ metadata.gz: c19673a2d24c9fa317035753b31f85ec1e69efb6a62a960344b08385f7a576c0d29f136760499989c2a0852c0bfbd6edfd0daf3210dbd14f167bcdd17ab1515f
7
+ data.tar.gz: 176fe8f019a0328916ca81921725d17d1a2e5578fe0cb11523e4e4fe3a50fd3fb8106b5668a6f6ef26c41691351e376a187929f6e59823194c5ad96f10eff5d6
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,3 @@
1
+ ## 0.1.0
2
+
3
+ - First release
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in cacheflow.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2017 Andrew Kane
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,30 @@
1
+ # Cacheflow
2
+
3
+ Colorized logging for Memcached and Redis
4
+
5
+ ![Screenshot](https://gist.githubusercontent.com/ankane/64d630db934c5222587794232a690864/raw/880b70fdbd2d11ccc8475f4616397184918852e8/console.png)
6
+
7
+ Works with the Rails cache, as well as [Dalli](https://github.com/petergoldstein/dalli) and [Redis](https://github.com/redis/redis-rb) clients directly
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application’s Gemfile:
12
+
13
+ ```ruby
14
+ gem 'cacheflow'
15
+ ```
16
+
17
+ When your log level is set to `DEBUG` (Rails default in development), all commands to Memcached and Redis are logged.
18
+
19
+ ## History
20
+
21
+ View the [changelog](https://github.com/ankane/cacheflow/blob/master/CHANGELOG.md)
22
+
23
+ ## Contributing
24
+
25
+ Everyone is encouraged to help improve this project. Here are a few ways you can help:
26
+
27
+ - [Report bugs](https://github.com/ankane/cacheflow/issues)
28
+ - Fix bugs and [submit pull requests](https://github.com/ankane/cacheflow/pulls)
29
+ - Write, clarify, or fix documentation
30
+ - Suggest or add new features
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task default: :test
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "cacheflow/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "cacheflow"
8
+ spec.version = Cacheflow::VERSION
9
+ spec.authors = ["Andrew Kane"]
10
+ spec.email = ["andrew@chartkick.com"]
11
+
12
+ spec.summary = "Colorized logging for Memcached and Redis"
13
+ spec.homepage = "https://github.com/ankane/cacheflow"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
16
+ f.match(%r{^(test|spec|features)/})
17
+ end
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "activesupport"
23
+
24
+ spec.add_development_dependency "bundler"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "minitest"
27
+ spec.add_development_dependency "dalli"
28
+ spec.add_development_dependency "redis"
29
+ end
@@ -0,0 +1,15 @@
1
+ require "active_support"
2
+ require "cacheflow/version"
3
+
4
+ module Cacheflow
5
+ def self.activate
6
+ require "cacheflow/memcached" if defined?(Dalli)
7
+ require "cacheflow/redis" if defined?(Redis)
8
+ end
9
+ end
10
+
11
+ if defined?(Rails)
12
+ require "cacheflow/railtie"
13
+ else
14
+ Cacheflow.activate
15
+ end
@@ -0,0 +1,27 @@
1
+ module Cacheflow
2
+ module Memcached
3
+ module Notifications
4
+ def request(op, *args)
5
+ payload = {
6
+ op: op,
7
+ args: args
8
+ }
9
+ ActiveSupport::Notifications.instrument("query.memcached", payload) do
10
+ super
11
+ end
12
+ end
13
+ end
14
+
15
+ class Instrumenter < ActiveSupport::LogSubscriber
16
+ def query(event)
17
+ return unless logger.debug?
18
+
19
+ name = "%s (%.2fms)" % ["Memcached", event.duration]
20
+ debug " #{color(name, BLUE, true)} #{event.payload[:op].to_s.upcase} #{event.payload[:args].join(" ")}"
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+ Dalli::Server.prepend(Cacheflow::Memcached::Notifications)
27
+ Cacheflow::Memcached::Instrumenter.attach_to(:memcached)
@@ -0,0 +1,7 @@
1
+ module Cashflow
2
+ class Railtie < Rails::Railtie
3
+ initializer "cacheflow" do
4
+ Cacheflow.activate
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,32 @@
1
+ module Cacheflow
2
+ module Redis
3
+ module Notifications
4
+ def logging(commands)
5
+ payload = {
6
+ commands: commands
7
+ }
8
+ ActiveSupport::Notifications.instrument("query.redis", payload) do
9
+ super
10
+ end
11
+ end
12
+ end
13
+
14
+ class Instrumenter < ActiveSupport::LogSubscriber
15
+ def query(event)
16
+ return unless logger.debug?
17
+
18
+ name = "%s (%.2fms)" % ["Redis", event.duration]
19
+
20
+ commands = []
21
+ event.payload[:commands].map do |op, *args|
22
+ commands << "#{op.to_s.upcase} #{args.join(" ")}".strip
23
+ end
24
+
25
+ debug " #{color(name, RED, true)} #{commands.join(" >> ")}"
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ Redis::Client.prepend(Cacheflow::Redis::Notifications)
32
+ Cacheflow::Redis::Instrumenter.attach_to(:redis)
@@ -0,0 +1,3 @@
1
+ module Cacheflow
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cacheflow
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Andrew Kane
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-09-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: dalli
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: redis
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description:
98
+ email:
99
+ - andrew@chartkick.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - CHANGELOG.md
106
+ - Gemfile
107
+ - LICENSE.txt
108
+ - README.md
109
+ - Rakefile
110
+ - cacheflow.gemspec
111
+ - lib/cacheflow.rb
112
+ - lib/cacheflow/memcached.rb
113
+ - lib/cacheflow/railtie.rb
114
+ - lib/cacheflow/redis.rb
115
+ - lib/cacheflow/version.rb
116
+ homepage: https://github.com/ankane/cacheflow
117
+ licenses: []
118
+ metadata: {}
119
+ post_install_message:
120
+ rdoc_options: []
121
+ require_paths:
122
+ - lib
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ requirements: []
134
+ rubyforge_project:
135
+ rubygems_version: 2.6.13
136
+ signing_key:
137
+ specification_version: 4
138
+ summary: Colorized logging for Memcached and Redis
139
+ test_files: []