battle_ship 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +21 -32
- data/Rakefile +3 -1
- data/battle_ship.gemspec +1 -1
- data/lib/battle_ship.rb +4 -0
- data/lib/battle_ship/version.rb +1 -1
- data/spec/lib/active_support_cache_subclass_spec.rb +2 -2
- data/spec/lib/battle_ship_spec.rb +14 -3
- data/spec/spec_helper.rb +8 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ef0a6a6b19a150b4ead60d3f5a75f3ab226c9f8
|
4
|
+
data.tar.gz: 3bdcdab074f21e0e577a18e43db96e6648515016
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 716a2bdee834065f1868323ba2693c4a7e73a50045a367feef1ff21cb6df47adb2ca86bd1eec4ec8e8bd868f1c17cf216476dded05c9789206b98b3d714abe20
|
7
|
+
data.tar.gz: 9c935394e24b0f379a123a58c28a4c853f3f6115651f7ca24e5cb1ee7b3ed02d5f8c4cec2bf43dec3ee0c8191c97f7f461a490cdd4bf127548a9b942b4c24a0c
|
data/README.md
CHANGED
@@ -1,28 +1,30 @@
|
|
1
1
|
# BattleShip
|
2
2
|
|
3
|
-
### Keep track of your cache hits & misses
|
4
|
-
|
5
3
|
#### Description
|
6
|
-
|
7
|
-
curious what your success is with your caching strategies. Perhaps you cache
|
8
|
-
some user objects, sessions, etc. How do you know whether it's working? What if
|
9
|
-
it's mostly misses?
|
4
|
+
The BattleShip gem answers the question "What is my cache hit rate?"
|
10
5
|
|
11
|
-
|
12
|
-
|
13
|
-
|
6
|
+
It does this by adding an increment to every cache read operation,
|
7
|
+
counting each read as either a hit (returned non-nil value) or miss (returned
|
8
|
+
nil). It stores the resulting numbers of hits and misses in the cache itself.
|
14
9
|
|
15
|
-
|
16
|
-
|
17
|
-
|
10
|
+
BattleShip assumes you are caching objects (such as a User or Session object). On a hit, it
|
11
|
+
will see the class name and increment the hit count at
|
12
|
+
```"#{returned_object.class}_hits"```, where returned_object is the object that
|
13
|
+
the cache call returns. On a miss, BattleShip assumes that the key represents
|
14
|
+
the class name (e.g. you called Rails.cache.read("user_1")), and increments the
|
15
|
+
miss counter accordingly (e.g. at "user_misses"). If you pass in a ```:namespace``` key in the options
|
16
|
+
hash, it will use that instead.
|
18
17
|
|
19
|
-
|
18
|
+
## Usage
|
20
19
|
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
Cache things just liek you do with Rails.cache methods already.
|
21
|
+
|
22
|
+
Access the hits by calling ```#hits``` on your particular cache implementation (e.g.
|
23
|
+
```Rails.cache.hits```) and passing in the namespace, e.g. User (either the string
|
24
|
+
or the classname).
|
25
|
+
Same deal with misses, but call ```#misses``` instead
|
24
26
|
|
25
|
-
|
27
|
+
#### Installation
|
26
28
|
|
27
29
|
Add this line to your application's Gemfile:
|
28
30
|
|
@@ -36,21 +38,9 @@ Or install it yourself as:
|
|
36
38
|
|
37
39
|
$ gem install battle_ship
|
38
40
|
|
39
|
-
## Usage
|
40
41
|
|
41
|
-
|
42
|
-
|
43
|
-
* When there's a cache hit, it will increment the value of the returned object's
|
44
|
-
class name plus the string "\_hits" (e.g. a User object's hits will be stored
|
45
|
-
in the cache at key ```"User_hits"```)
|
46
|
-
* When there's a cache miss, BattleShip doesn't know exactly the class you were
|
47
|
-
expecting, so it assumes that you either: (1) Passed in a namespace key in
|
48
|
-
the options hash, or (2) Named your key such that the first underscore occurs
|
49
|
-
after the name of the class (e.g. "User_123").
|
50
|
-
* Access the hits by calling ```#hits``` on your particular cache implementation (e.g.
|
51
|
-
```Rails.cache.hits```) and passing in the namespace, e.g. User (either the string
|
52
|
-
or the classname).
|
53
|
-
* Same deal with misses, but call ```#misses``` instead
|
42
|
+
#### Warnings, Caveats, etc.
|
43
|
+
If you are using a cache store that does not subclass ActiveSupport::Cache::Store, please add an initializer file in ```config/initializers``` that calls ```BattleShip.include!```
|
54
44
|
|
55
45
|
|
56
46
|
## Contributing
|
@@ -64,6 +54,5 @@ or the classname).
|
|
64
54
|
## To Do
|
65
55
|
|
66
56
|
1. Add performance measurements
|
67
|
-
2. Add rails example app
|
68
57
|
3. Add config option for turning on/off
|
69
58
|
4. Add config option for setting time-frame of hits/misses
|
data/Rakefile
CHANGED
data/battle_ship.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["DavidRagone"]
|
10
10
|
spec.email = ["dmragone@gmail.com"]
|
11
11
|
spec.description = %q{Adds counters to cache when successful read operation completes in order to track Rails.cache hits & misses}
|
12
|
-
spec.summary = %q{
|
12
|
+
spec.summary = %q{Keep track of cache hits and misses}
|
13
13
|
spec.homepage = "https://github.com/DavidRagone/BattleShip"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
data/lib/battle_ship.rb
CHANGED
data/lib/battle_ship/version.rb
CHANGED
@@ -24,13 +24,13 @@ describe ActiveSupport::Cache::Something do
|
|
24
24
|
|
25
25
|
context ".read" do
|
26
26
|
it "increments the related counter on hits" do
|
27
|
-
cache.should_receive(:increment).with("User_hits")
|
27
|
+
cache.should_receive(:increment).with("User_hits", 1)
|
28
28
|
cache.write("user_1", user)
|
29
29
|
cache.read("user_1").should eq user
|
30
30
|
end
|
31
31
|
|
32
32
|
it "increments the related counter on misses" do
|
33
|
-
cache.should_receive(:increment).with("User_misses")
|
33
|
+
cache.should_receive(:increment).with("User_misses", 1)
|
34
34
|
cache.read("user_1").should eq nil
|
35
35
|
end
|
36
36
|
end
|
@@ -1,19 +1,18 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
# For tests of #read_entry, see spec/lib/active_support_cache_subclass_spec.rb
|
4
3
|
describe BattleShip do
|
5
4
|
let(:dummy) { Class.new { prepend(BattleShip) }.new }
|
6
5
|
|
7
6
|
describe "#hits" do
|
8
7
|
it "reads, skipping increment" do
|
9
|
-
dummy.should_receive(:read).with("Foo_hits", { skip_increment: true })
|
8
|
+
dummy.should_receive(:read).with("Foo_hits", { skip_increment: true, raw: true })
|
10
9
|
dummy.hits("Foo")
|
11
10
|
end
|
12
11
|
end
|
13
12
|
|
14
13
|
describe "#misses" do
|
15
14
|
it "reads, skipping increment" do
|
16
|
-
dummy.should_receive(:read).with("Foo_misses", { skip_increment: true })
|
15
|
+
dummy.should_receive(:read).with("Foo_misses", { skip_increment: true, raw: true })
|
17
16
|
dummy.misses("Foo")
|
18
17
|
end
|
19
18
|
end
|
@@ -44,4 +43,16 @@ describe BattleShip do
|
|
44
43
|
end
|
45
44
|
end
|
46
45
|
end
|
46
|
+
|
47
|
+
describe ".include!" do
|
48
|
+
subject { BattleShip.include! }
|
49
|
+
it "forcefully prepends self to Rails.cache.class" do
|
50
|
+
klass = double
|
51
|
+
cache = double
|
52
|
+
Rails.should_receive(:cache) { cache }
|
53
|
+
cache.should_receive(:class) { klass }
|
54
|
+
klass.should_receive(:class_eval).with("prepend BattleShip")
|
55
|
+
subject
|
56
|
+
end
|
57
|
+
end
|
47
58
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: battle_ship
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- DavidRagone
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-09-
|
11
|
+
date: 2013-09-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -123,7 +123,7 @@ rubyforge_project:
|
|
123
123
|
rubygems_version: 2.0.3
|
124
124
|
signing_key:
|
125
125
|
specification_version: 4
|
126
|
-
summary:
|
126
|
+
summary: Keep track of cache hits and misses
|
127
127
|
test_files:
|
128
128
|
- spec/lib/active_support_cache_subclass_spec.rb
|
129
129
|
- spec/lib/battle_ship_spec.rb
|