cache_stache 0.1.0 → 0.1.1
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 +4 -4
- data/README.md +5 -90
- data/lib/cache_stache/version.rb +1 -1
- data/spec/cache_stache_helper.rb +1 -0
- data/spec/unit/configuration_spec.rb +1 -0
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6d78eea9e2e19c6f95024644eaea2dc942993225c42ca636473e19e46fd6f449
|
|
4
|
+
data.tar.gz: 6156b5fe4adc1756b1ebf1fe92e413ab16bba3589557e26d17efe3ef2fa18dbf
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b976afa17c53451ea8b6aa57e6d15d88f097f9fd72bc8bd420b91911f06af686f7f7693eee76f9981fd1644b3abd3694c942c6a1e28e764ec97b4148a8062f47
|
|
7
|
+
data.tar.gz: d31764e21a67a0b2006a59593f1b4757f95a731817d3c8cf0d6af802bef0e7afcbc9e5d0b30f1069d77b6606b60a1f62b6f24315ee9fafb8b77e20a6c71a2ff1
|
data/README.md
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://github.com/speedshop/cache_stache/actions/workflows/ci.yml)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Have you ever had to work with a Redis cache provider which doesn't provide hitrate stats? It's a bummer. Use this gem!
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
CacheStache tracks cache hit rates for Rails apps. It counts how often your cache has data (hits) and how often it does not (misses). You can view these counts on a web page.
|
|
8
8
|
|
|
9
9
|
## Features
|
|
10
10
|
|
|
@@ -42,7 +42,7 @@ A higher hit rate means your app finds data in the cache more often. This means
|
|
|
42
42
|
|
|
43
43
|
4. Restart Rails and go to `/cache-stache`.
|
|
44
44
|
|
|
45
|
-
### Add
|
|
45
|
+
### Add Authentication
|
|
46
46
|
|
|
47
47
|
You can add a password to the web page:
|
|
48
48
|
|
|
@@ -104,7 +104,7 @@ end
|
|
|
104
104
|
| `bucket_seconds` | 5 minutes | Size of each time bucket |
|
|
105
105
|
| `retention_seconds` | 7 days | How long to keep data |
|
|
106
106
|
| `max_buckets` | 288 | Maximum number of buckets to query |
|
|
107
|
-
| `sample_rate` | 1.0 |
|
|
107
|
+
| `sample_rate` | 1.0 | Sample events |
|
|
108
108
|
| `enabled` | true | Turn tracking on or off |
|
|
109
109
|
| `use_rack_after_reply` | false | Wait to write until after response |
|
|
110
110
|
|
|
@@ -126,37 +126,6 @@ end
|
|
|
126
126
|
|
|
127
127
|
A cache key can match more than one keyspace.
|
|
128
128
|
|
|
129
|
-
## Web Page
|
|
130
|
-
|
|
131
|
-
The web page shows:
|
|
132
|
-
|
|
133
|
-
- Total hit rate
|
|
134
|
-
- Hit rate for each keyspace
|
|
135
|
-
- Current settings
|
|
136
|
-
- Size of stored data
|
|
137
|
-
|
|
138
|
-
Time windows: 5m, 15m, 1h (default), 6h, 1d, 1w.
|
|
139
|
-
|
|
140
|
-
Click a keyspace name to see more detail.
|
|
141
|
-
|
|
142
|
-
## How It Works
|
|
143
|
-
|
|
144
|
-
```
|
|
145
|
-
Rails.cache.fetch(...)
|
|
146
|
-
-> Rails sends an event
|
|
147
|
-
-> CacheStache counts it
|
|
148
|
-
-> CacheStache stores the count
|
|
149
|
-
-> Web page shows the counts
|
|
150
|
-
```
|
|
151
|
-
|
|
152
|
-
1. **Counting**: CacheStache listens for cache events. It skips its own cache calls.
|
|
153
|
-
|
|
154
|
-
2. **Buckets**: Times are rounded down to `bucket_seconds`. Each event adds to hit or miss counts.
|
|
155
|
-
|
|
156
|
-
3. **Storage**: Counts are stored with keys like `cache_stache:v1:production:1234567890`. Each bucket expires after `retention_seconds`.
|
|
157
|
-
|
|
158
|
-
4. **Reading**: The web page reads all buckets and adds them up.
|
|
159
|
-
|
|
160
129
|
## Query Stats in Code
|
|
161
130
|
|
|
162
131
|
You can get stats from Ruby code:
|
|
@@ -171,61 +140,7 @@ results[:overall][:misses] # => 210
|
|
|
171
140
|
results[:keyspaces][:profiles][:hit_rate_percent] # => 92.1
|
|
172
141
|
```
|
|
173
142
|
|
|
174
|
-
## Test Data
|
|
175
|
-
|
|
176
|
-
Make fake data with:
|
|
177
|
-
|
|
178
|
-
```bash
|
|
179
|
-
rails runner lib/cache_stache/bin/test_day_simulation.rb
|
|
180
|
-
```
|
|
181
|
-
|
|
182
|
-
This makes 24 hours of fake cache events. Then go to `/cache-stache` to see it.
|
|
183
|
-
|
|
184
143
|
## Limits
|
|
185
144
|
|
|
186
|
-
- The `sample_rate` setting does nothing yet.
|
|
187
145
|
- Only cache reads are tracked. Writes and deletes are not.
|
|
188
|
-
- If you have two cache stores of the same type, their events will be mixed.
|
|
189
|
-
|
|
190
|
-
## Files
|
|
191
|
-
|
|
192
|
-
```
|
|
193
|
-
lib/cache_stache/
|
|
194
|
-
├── app/ # Web page views and code
|
|
195
|
-
├── bin/ # Test scripts
|
|
196
|
-
├── config/ # Routes
|
|
197
|
-
├── lib/ # Gem/engine Ruby code
|
|
198
|
-
│ ├── cache_stache.rb
|
|
199
|
-
│ ├── cache_stache/
|
|
200
|
-
│ └── generators/
|
|
201
|
-
├── Gemfile # Standalone bundler entrypoint
|
|
202
|
-
├── cache_stache.gemspec
|
|
203
|
-
├── Rakefile
|
|
204
|
-
├── spec/ # Tests
|
|
205
|
-
├── tasks/ # Rake tasks
|
|
206
|
-
```
|
|
207
|
-
|
|
208
|
-
## Running Specs (Standalone)
|
|
209
|
-
|
|
210
|
-
CacheStache can be tested independently from the host Rails app:
|
|
211
|
-
|
|
212
|
-
```bash
|
|
213
|
-
cd lib/cache_stache
|
|
214
|
-
bundle install
|
|
215
|
-
bundle exec rspec
|
|
216
|
-
```
|
|
217
|
-
|
|
218
|
-
From the host app root, you can also run the engine suite without `cd`:
|
|
219
|
-
|
|
220
|
-
```bash
|
|
221
|
-
BUNDLE_GEMFILE=lib/cache_stache/Gemfile bundle exec rspec --options lib/cache_stache/.rspec lib/cache_stache/spec
|
|
222
|
-
```
|
|
223
|
-
|
|
224
|
-
## Run Tests
|
|
225
|
-
|
|
226
|
-
```bash
|
|
227
|
-
cd lib/cache_stache
|
|
228
|
-
bundle exec rspec
|
|
229
|
-
```
|
|
230
|
-
|
|
231
|
-
Tests are in `lib/cache_stache/spec/`. They do not need Redis.
|
|
146
|
+
- If you have two cache stores of the same type (redis, memcached, etc), their events will be mixed.
|
data/lib/cache_stache/version.rb
CHANGED
data/spec/cache_stache_helper.rb
CHANGED
|
@@ -55,6 +55,7 @@ module CacheStacheTestHelpers
|
|
|
55
55
|
c.retention_seconds = options.fetch(:retention_seconds, 3600)
|
|
56
56
|
c.sample_rate = options.fetch(:sample_rate, 1.0)
|
|
57
57
|
c.use_rack_after_reply = options.fetch(:use_rack_after_reply, false)
|
|
58
|
+
c.enabled = options.fetch(:enabled, true)
|
|
58
59
|
|
|
59
60
|
keyspaces.each do |name, keyspace_config|
|
|
60
61
|
c.keyspace(name) do
|
|
@@ -11,6 +11,7 @@ RSpec.describe CacheStache::Configuration do
|
|
|
11
11
|
before do
|
|
12
12
|
allow(ENV).to receive(:fetch).and_call_original
|
|
13
13
|
allow(ENV).to receive(:fetch).with("CACHE_STACHE_REDIS_URL").and_return(default_redis_url)
|
|
14
|
+
allow(ENV).to receive(:fetch).with("RAILS_ENV", "development").and_return("development")
|
|
14
15
|
end
|
|
15
16
|
|
|
16
17
|
it { expect(config.bucket_seconds).to eq(5.minutes.to_i) }
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: cache_stache
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- CacheStache contributors
|
|
@@ -13,14 +13,14 @@ dependencies:
|
|
|
13
13
|
name: rails
|
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
|
15
15
|
requirements:
|
|
16
|
-
- - "
|
|
16
|
+
- - ">="
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
18
|
version: '7.0'
|
|
19
19
|
type: :runtime
|
|
20
20
|
prerelease: false
|
|
21
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
22
22
|
requirements:
|
|
23
|
-
- - "
|
|
23
|
+
- - ">="
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
25
|
version: '7.0'
|
|
26
26
|
- !ruby/object:Gem::Dependency
|