lock_and_cache 2.1.0 → 2.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/CHANGELOG +6 -0
- data/README.md +25 -0
- data/lib/lock_and_cache.rb +1 -0
- data/lib/lock_and_cache/version.rb +1 -1
- data/spec/lock_and_cache_spec.rb +8 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19f9d5d8d273859b3802392c2c716bf2a60b897f
|
4
|
+
data.tar.gz: 45727c9b74dd4fb11b6e8e6fa9dd2655ae01f231
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f27d00caceafde847297680ca8e12c81d2d1f006ff93c50a1f711117d75bd0a1a73a6d118caf29a9cafe7adf5084d6ab66843a2af70e57fec2bd4323a228ad15
|
7
|
+
data.tar.gz: 7b66cc2ed3a4f4da75dfec0b22afb299163e999f5791cb59ecc931883910412d7a34845790d6abf2e9e4654b3e5821d2deb3098df1796e090d5a71364dda8161
|
data/CHANGELOG
CHANGED
data/README.md
CHANGED
@@ -15,6 +15,31 @@ Lock and cache using redis!
|
|
15
15
|
|
16
16
|
We use [`lock_and_cache`](https://rubygems.org/gems/lock_and_cache) for [big data-driven marketing at Faraday](http://faraday.io).
|
17
17
|
|
18
|
+
## TOC
|
19
|
+
|
20
|
+
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
|
21
|
+
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
|
22
|
+
|
23
|
+
|
24
|
+
- [Theory](#theory)
|
25
|
+
- [Practice](#practice)
|
26
|
+
- [Locking](#locking)
|
27
|
+
- [Caching](#caching)
|
28
|
+
- [Standalone mode](#standalone-mode)
|
29
|
+
- [Context mode](#context-mode)
|
30
|
+
- [Special features](#special-features)
|
31
|
+
- [Locking of course!](#locking-of-course)
|
32
|
+
- [Heartbeat](#heartbeat)
|
33
|
+
- [Context mode](#context-mode-1)
|
34
|
+
- [nil_expires](#nil_expires)
|
35
|
+
- [Tunables](#tunables)
|
36
|
+
- [Few dependencies](#few-dependencies)
|
37
|
+
- [Wishlist](#wishlist)
|
38
|
+
- [Contributing](#contributing)
|
39
|
+
- [Copyright](#copyright)
|
40
|
+
|
41
|
+
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
42
|
+
|
18
43
|
## Theory
|
19
44
|
|
20
45
|
`lock_and_cache`...
|
data/lib/lock_and_cache.rb
CHANGED
@@ -54,6 +54,7 @@ module LockAndCache
|
|
54
54
|
# @note A single hash arg is treated as a cached key. `LockAndCache.lock_and_cache(foo: :bar, expires: 100)` will be treated as a cache key of `foo: :bar, expires: 100` (which is probably wrong!!!). `LockAndCache.lock_and_cache({foo: :bar}, expires: 100)` will be treated as a cache key of `foo: :bar` and options `expires: 100`. This is the opposite of context mode and is true because we don't have any context to set the cache key from otherwise.
|
55
55
|
def LockAndCache.lock_and_cache(*key_parts_and_options, &blk)
|
56
56
|
options = (key_parts_and_options.last.is_a?(Hash) && key_parts_and_options.length > 1) ? key_parts_and_options.pop : {}
|
57
|
+
raise "need a cache key" unless key_parts_and_options.length > 0
|
57
58
|
key = LockAndCache::Key.new key_parts_and_options
|
58
59
|
action = LockAndCache::Action.new key, options, blk
|
59
60
|
action.perform
|
data/spec/lock_and_cache_spec.rb
CHANGED
@@ -287,6 +287,14 @@ describe LockAndCache do
|
|
287
287
|
expect(count).to eq(2)
|
288
288
|
end
|
289
289
|
|
290
|
+
it "requires a key" do
|
291
|
+
expect do
|
292
|
+
LockAndCache.lock_and_cache do
|
293
|
+
raise "this won't happen"
|
294
|
+
end
|
295
|
+
end.to raise_error(/need/)
|
296
|
+
end
|
297
|
+
|
290
298
|
it 'allows clearing' do
|
291
299
|
count = 0
|
292
300
|
expect(LockAndCache.lock_and_cache('hello') { count += 1 }).to eq(1)
|