lock_and_cache 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +6 -0
- data/lib/lock_and_cache.rb +6 -0
- data/lib/lock_and_cache/version.rb +1 -1
- 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: 2fe1e1aa249ac319cc720916c9f3677caad588c7
|
4
|
+
data.tar.gz: 4cc645768c09dbdadecf4acc1fd725f74f0868a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f9560ee842aaaf400e9685066b7758ceb5c654ec86e218f8f79ad75e9d9e9f2ab1df602e4645a031323c969666449c7b8157c6cf0e08eef8252e7fa3a235cf77
|
7
|
+
data.tar.gz: 7b7f13f14b8a6fd2a03a4dbd860b1edd5fb9090fcbdc9e6b8c1f4f64c88ecd2a98fd02eaf2fb575f5e8ee5c59d9e0e3973fb2abf8cf13c8c902d0433a79b7473
|
data/CHANGELOG
CHANGED
data/lib/lock_and_cache.rb
CHANGED
@@ -12,14 +12,20 @@ module LockAndCache
|
|
12
12
|
alias_method unlocked_method_id, method_id
|
13
13
|
|
14
14
|
define_method method_id do |*args|
|
15
|
+
debug = (ENV['LOCK_AND_CACHE_DEBUG'] == 'true')
|
15
16
|
lock_key = [self.class.name, method_id, HashDigest.digest3([as_cache_key]+args)].join('/')
|
17
|
+
debug_lock_key = [self.class.name, method_id, [as_cache_key]+args].join('/') if debug
|
18
|
+
Thread.exclusive { $stderr.puts "[lock_and_cache] A #{debug_lock_key}" } if debug
|
16
19
|
if cache_method_cached?(method_id, args)
|
17
20
|
return send(method_id, *args) # which will be the cached version
|
18
21
|
end
|
22
|
+
Thread.exclusive { $stderr.puts "[lock_and_cache] B #{debug_lock_key}" } if debug
|
19
23
|
ActiveRecord::Base.with_advisory_lock(lock_key) do
|
24
|
+
Thread.exclusive { $stderr.puts "[lock_and_cache] C #{debug_lock_key}" } if debug
|
20
25
|
if cache_method_cached?(method_id, args)
|
21
26
|
send method_id, *args # which will be the cached version
|
22
27
|
else
|
28
|
+
Thread.exclusive { $stderr.puts "[lock_and_cache] D #{debug_lock_key}" } if debug
|
23
29
|
send unlocked_method_id, *args
|
24
30
|
end
|
25
31
|
end
|