@@ -21,17 +21,18 @@ def lock_was_acquired?
21
21
LockStackItem = Struct . new ( :name , :shared )
22
22
23
23
class Base
24
- attr_reader :connection , :lock_name , :timeout_seconds , :shared , :transaction
24
+ attr_reader :connection , :lock_name , :timeout_seconds , :shared , :transaction , :disable_query_cache
25
25
26
26
def initialize ( connection , lock_name , options )
27
27
options = { timeout_seconds : options } unless options . respond_to? ( :fetch )
28
- options . assert_valid_keys :timeout_seconds , :shared , :transaction
28
+ options . assert_valid_keys :timeout_seconds , :shared , :transaction , :disable_query_cache
29
29
30
30
@connection = connection
31
31
@lock_name = lock_name
32
32
@timeout_seconds = options . fetch ( :timeout_seconds , nil )
33
33
@shared = options . fetch ( :shared , false )
34
34
@transaction = options . fetch ( :transaction , false )
35
+ @disable_query_cache = options . fetch ( :disable_query_cache , false )
35
36
end
36
37
37
38
def lock_str
@@ -53,6 +54,16 @@ def already_locked?
53
54
end
54
55
55
56
def with_advisory_lock_if_needed ( &block )
57
+ if disable_query_cache
58
+ return lock_and_yield do
59
+ ActiveRecord ::Base . uncached ( &block )
60
+ end
61
+ end
62
+
63
+ lock_and_yield ( &block )
64
+ end
65
+
66
+ def lock_and_yield ( &block )
56
67
if already_locked?
57
68
Result . new ( true , yield )
58
69
elsif timeout_seconds == 0
0 commit comments