lock_and_cache 4.0.5 → 4.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +5 -1
- data/lib/lock_and_cache.rb +8 -0
- data/lib/lock_and_cache/key.rb +4 -0
- data/lib/lock_and_cache/version.rb +1 -1
- data/spec/lock_and_cache_spec.rb +6 -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: 486140a35280062778f6f70680406c74798a8a68
|
4
|
+
data.tar.gz: 262bc8de8f1990818ed04b4e964fe46c4366256a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: caf0ac825c8b69ce6d15f4af75aa1f6a7a8e0902184c80dafb04a0de1b9dcebf05ec6018b75c27d4b845cc7d7f5e00f3ca48c7daee1c6a5edb90078561638058
|
7
|
+
data.tar.gz: 77ed0de21b2fafbc9c36b50ce5b390e1d8090c4c1956c079f83ef6fd6a26d3d1db7c71ead492c06328d9c68808706807f377de1ec92651cea8d3fe08e3a521b0
|
data/CHANGELOG
CHANGED
data/lib/lock_and_cache.rb
CHANGED
@@ -83,6 +83,14 @@ module LockAndCache
|
|
83
83
|
key.locked?
|
84
84
|
end
|
85
85
|
|
86
|
+
# Check if a key is cached already
|
87
|
+
#
|
88
|
+
# @note Standalone mode. See also "context mode," where you mix LockAndCache into a class and call it from within its methods.
|
89
|
+
def LockAndCache.cached?(*key_parts)
|
90
|
+
key = LockAndCache::Key.new key_parts
|
91
|
+
key.cached?
|
92
|
+
end
|
93
|
+
|
86
94
|
# @param seconds [Numeric] Maximum wait time to get a lock
|
87
95
|
#
|
88
96
|
# @note Can be overridden by putting `max_lock_wait:` in your call to `#lock_and_cache`
|
data/lib/lock_and_cache/key.rb
CHANGED
@@ -101,6 +101,10 @@ module LockAndCache
|
|
101
101
|
LockAndCache.storage.exists lock_digest
|
102
102
|
end
|
103
103
|
|
104
|
+
def cached?
|
105
|
+
LockAndCache.storage.exists digest
|
106
|
+
end
|
107
|
+
|
104
108
|
def clear
|
105
109
|
LockAndCache.logger.debug { "[lock_and_cache] clear #{debug} #{Base64.encode64(digest).strip} #{Digest::SHA1.hexdigest digest}" }
|
106
110
|
storage = LockAndCache.storage
|
data/spec/lock_and_cache_spec.rb
CHANGED
@@ -337,6 +337,12 @@ describe LockAndCache do
|
|
337
337
|
expect(count).to eq(1)
|
338
338
|
end
|
339
339
|
|
340
|
+
it "can be queried for cached?" do
|
341
|
+
expect(LockAndCache.cached?('hello')).to be_falsy
|
342
|
+
LockAndCache.lock_and_cache('hello') { nil }
|
343
|
+
expect(LockAndCache.cached?('hello')).to be_truthy
|
344
|
+
end
|
345
|
+
|
340
346
|
it 'allows expiry' do
|
341
347
|
count = 0
|
342
348
|
expect(LockAndCache.lock_and_cache('hello', expires: 1) { count += 1 }).to eq(1)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lock_and_cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0.
|
4
|
+
version: 4.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Seamus Abshere
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-04-
|
11
|
+
date: 2017-04-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|