readthis 1.4.1 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -3
- data/lib/readthis/cache.rb +43 -0
- data/lib/readthis/version.rb +1 -1
- data/spec/readthis/cache_spec.rb +26 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d99b745b536b4761198212736eba995173cf7dd0
|
4
|
+
data.tar.gz: fb66dd2f67cc90114ad5037ea10b684722d6d468
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 992a39d5b3c6fde1796dbd8ac8dc8c03aa44cd79152a15e6b1ca553327d4dec95f754ddb68a2275aa636d75d13658e43b712ebd95ae4b49ae21f6a164ad66b87
|
7
|
+
data.tar.gz: e5521f55739341901c7bbe6d9743127686643ca44cb82bf338f046a81fd16a522f364ee757e5f548f3ed9c647b495904c0faa1144470e47f4610f510cebc23e1
|
data/README.md
CHANGED
@@ -183,9 +183,7 @@ Rails.cache.pool.with { |client| client.expire('foo-key', 60) }
|
|
183
183
|
Readthis supports all of standard cache methods except for the following:
|
184
184
|
|
185
185
|
* `cleanup` - Redis does this with TTL or LRU already.
|
186
|
-
* `
|
187
|
-
Redis. They are linear time and only support basic globbing.
|
188
|
-
* `mute` and `silence!` - You can subscribe to the events `/cache*.active_support/`
|
186
|
+
* `mute` and `silence!` - You must subscribe to the events `/cache*.active_support/`
|
189
187
|
with `ActiveSupport::Notifications` to [log cache calls manually][notifications].
|
190
188
|
|
191
189
|
[notifications]: https://github.com/sorentwo/readthis/issues/22#issuecomment-142595938
|
data/lib/readthis/cache.rb
CHANGED
@@ -115,6 +115,49 @@ module Readthis
|
|
115
115
|
end
|
116
116
|
end
|
117
117
|
|
118
|
+
# Delete all values that match a given pattern. The pattern must be defined
|
119
|
+
# using Redis compliant globs. The following examples are borrowed from the
|
120
|
+
# `KEYS` documentation:
|
121
|
+
#
|
122
|
+
# * `h?llo` matches hello, hallo and hxllo
|
123
|
+
# * `h*llo` matches hllo and heeeello
|
124
|
+
# * `h[ae]llo` matches hello and hallo, but not hillo
|
125
|
+
# * `h[^e]llo` matches hallo, hbllo, ... but not hello
|
126
|
+
# * `h[a-b]llo` matches hallo and hbllo
|
127
|
+
#
|
128
|
+
# Note that `delete_matched` does *not* use the `KEYS` command, making it
|
129
|
+
# safe for use in production.
|
130
|
+
#
|
131
|
+
# @param [String] pattern The glob pattern for matching keys
|
132
|
+
# @option [String] :namespace Prepend a namespace to the pattern
|
133
|
+
# @option [Number] :count Configure the number of keys deleted at once
|
134
|
+
#
|
135
|
+
# @example Delete all 'cat' keys
|
136
|
+
#
|
137
|
+
# cache.delete_matched('*cats') #=> 47
|
138
|
+
# cache.delete_matched('*dogs') #=> 0
|
139
|
+
#
|
140
|
+
def delete_matched(pattern, options = {})
|
141
|
+
namespaced = namespaced_key(pattern, merged_options(options))
|
142
|
+
|
143
|
+
invoke(:delete, pattern) do |store|
|
144
|
+
cursor = nil
|
145
|
+
count = options.fetch(:count, 1000)
|
146
|
+
deleted = 0
|
147
|
+
|
148
|
+
until cursor == '0'.freeze
|
149
|
+
cursor, matched = store.scan(cursor || 0, match: namespaced, count: count)
|
150
|
+
|
151
|
+
if matched.any?
|
152
|
+
store.del(*matched)
|
153
|
+
deleted += matched.length
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
deleted
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
118
161
|
# Fetches data from the cache, using the given key. If there is data in the
|
119
162
|
# cache with the given key, then that data is returned.
|
120
163
|
#
|
data/lib/readthis/version.rb
CHANGED
data/spec/readthis/cache_spec.rb
CHANGED
@@ -327,6 +327,32 @@ RSpec.describe Readthis::Cache do
|
|
327
327
|
end
|
328
328
|
end
|
329
329
|
|
330
|
+
describe '#delete_matched' do
|
331
|
+
it 'deletes all matching keys' do
|
332
|
+
cache.write('tomcat', 'cat')
|
333
|
+
cache.write('wildcat', 'cat')
|
334
|
+
cache.write('bobcat', 'cat')
|
335
|
+
cache.write('cougar', 'cat')
|
336
|
+
|
337
|
+
expect(cache.delete_matched('tomcat')).to eq(1)
|
338
|
+
expect(cache.read('tomcat')).to be_nil
|
339
|
+
expect(cache.read('bobcat')).not_to be_nil
|
340
|
+
expect(cache.read('wildcat')).not_to be_nil
|
341
|
+
|
342
|
+
expect(cache.delete_matched('*cat', count: 1)).to eq(2)
|
343
|
+
expect(cache.read('wildcat')).to be_nil
|
344
|
+
expect(cache.read('bobcat')).to be_nil
|
345
|
+
|
346
|
+
expect(cache.delete_matched('*cat')).to eq(0)
|
347
|
+
end
|
348
|
+
|
349
|
+
it 'respects namespacing when matching keys' do
|
350
|
+
cache.write('tomcat', 'cat', namespace: 'feral')
|
351
|
+
|
352
|
+
expect(cache.delete_matched('tom*', namespace: 'feral')).to eq(1)
|
353
|
+
end
|
354
|
+
end
|
355
|
+
|
330
356
|
describe '#increment' do
|
331
357
|
it 'atomically increases the stored integer' do
|
332
358
|
cache.write('counter', 10)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: readthis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Parker Selbert
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|