lock_and_cache 4.0.5 → 4.0.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c01496db7fee2406fdd535409a2ef112969f9243
4
- data.tar.gz: becfd8a7f466108d3f592bfe7c8f51e92fcb2a8f
3
+ metadata.gz: 486140a35280062778f6f70680406c74798a8a68
4
+ data.tar.gz: 262bc8de8f1990818ed04b4e964fe46c4366256a
5
5
  SHA512:
6
- metadata.gz: d401e8f1d206a4496fd911a863d8ad78ac2aa4354e94d3a608c428667adbdd92fe5d3870ad4f4913a8c90183a9776ddba90ed931ea4fea705ffbb14e953a39e6
7
- data.tar.gz: 85a4e1bf664f77d1bf4ea4d6d186593e288ffe488578db96d4090f16bee36b9a2c79fea3bd271b9b64ad3dfae9b68d3c34c9557615f2b343bf67eef1c757f079
6
+ metadata.gz: caf0ac825c8b69ce6d15f4af75aa1f6a7a8e0902184c80dafb04a0de1b9dcebf05ec6018b75c27d4b845cc7d7f5e00f3ca48c7daee1c6a5edb90078561638058
7
+ data.tar.gz: 77ed0de21b2fafbc9c36b50ce5b390e1d8090c4c1956c079f83ef6fd6a26d3d1db7c71ead492c06328d9c68808706807f377de1ec92651cea8d3fe08e3a521b0
data/CHANGELOG CHANGED
@@ -1,9 +1,13 @@
1
- unreleased
1
+ 4.0.6
2
2
 
3
3
  * ?
4
4
 
5
5
  * Don't test on ruby 2.1
6
6
 
7
+ * Enhancements
8
+
9
+ * LockAndCache.cached?(*key_parts) to check if a value is cached
10
+
7
11
  4.0.5 / 2017-04-01
8
12
 
9
13
  * Enhancements
@@ -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`
@@ -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
@@ -1,3 +1,3 @@
1
1
  module LockAndCache
2
- VERSION = '4.0.5'
2
+ VERSION = '4.0.6'
3
3
  end
@@ -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.5
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-01 00:00:00.000000000 Z
11
+ date: 2017-04-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport