simple_cache_lock 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/README.md +3 -2
- data/lib/simple_cache_lock/client.rb +8 -3
- data/lib/simple_cache_lock/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c879c36b77e537dd0ac719a378af55edf8267cdb1174a57455a1c8011d5dd48f
|
4
|
+
data.tar.gz: 2b79e4f23d7d305d005f296b97d424f5aee77139a0c7166f06070a0e04408164
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1a210591fc0460db2d14ac4345501027933e830ef4df8dbff9fac0da831f2831eac8d71405f66aec611ca378edbf89cc4b18abb6fcf0f49b55df5aa68a6c48c
|
7
|
+
data.tar.gz: abd5e232c390db9af9245659ce4b3d8a362e35485fa2daf3a2052285173dac0cd211ffa300b398d6d9330c281ef19467889b58bcb0f0a0232f3acce16ba2ab80
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
# SimpleCacheLock
|
2
2
|
|
3
|
-
|
3
|
+
Warn: No testing added!!! Use at your risk
|
4
4
|
|
5
|
-
|
5
|
+
Lock and wait your cache until it finished. don't let concurrent processes write
|
6
|
+
same cache_key. make them to wait instead.
|
6
7
|
|
7
8
|
## Installation
|
8
9
|
|
@@ -16,13 +16,18 @@ module SimpleCacheLock
|
|
16
16
|
|
17
17
|
if is_locked == false
|
18
18
|
Timeout::timeout(wait_timeout) {
|
19
|
-
|
20
|
-
|
19
|
+
loop do
|
20
|
+
is_locked = redlock.lock(lock_key, wait_lock_timeout)
|
21
|
+
if is_locked == false
|
22
|
+
sleep rand
|
23
|
+
else
|
24
|
+
break
|
25
|
+
end
|
21
26
|
end
|
22
27
|
}
|
23
28
|
|
24
29
|
if cache_store.exist? content_cache_key
|
25
|
-
redlock.unlock(is_locked)
|
30
|
+
redlock.unlock(is_locked) unless is_locked
|
26
31
|
return cache_store.read key
|
27
32
|
end
|
28
33
|
end
|