File tree Expand file tree Collapse file tree 3 files changed +24
-4
lines changed Expand file tree Collapse file tree 3 files changed +24
-4
lines changed Original file line number Diff line number Diff line change
1
+ * Make the order of read_multi and write_multi notifications for ` Cache::Store#fetch_multi ` operations match the order they are executed in.
2
+
3
+ * Adam Renberg Tamm*
4
+
1
5
* Make return values of ` Cache::Store#write ` consistent.
2
6
3
7
The return value was not specified before. Now it returns ` true ` on a successful write,
Original file line number Diff line number Diff line change @@ -605,14 +605,14 @@ def fetch_multi(*names)
605
605
options = names . extract_options!
606
606
options = merged_options ( options )
607
607
608
- instrument_multi :read_multi , names , options do |payload |
608
+ writes = { }
609
+ ordered = instrument_multi :read_multi , names , options do |payload |
609
610
if options [ :force ]
610
611
reads = { }
611
612
else
612
613
reads = read_multi_entries ( names , **options )
613
614
end
614
615
615
- writes = { }
616
616
ordered = names . index_with do |name |
617
617
reads . fetch ( name ) { writes [ name ] = yield ( name ) }
618
618
end
@@ -621,10 +621,12 @@ def fetch_multi(*names)
621
621
payload [ :hits ] = reads . keys
622
622
payload [ :super_operation ] = :fetch_multi
623
623
624
- write_multi ( writes , options )
625
-
626
624
ordered
627
625
end
626
+
627
+ write_multi ( writes , options )
628
+
629
+ ordered
628
630
end
629
631
630
632
# Writes the value to the cache with the key. The value must be supported
Original file line number Diff line number Diff line change @@ -34,6 +34,20 @@ def test_instrumentation_with_fetch_multi_as_super_operation
34
34
assert_equal @cache . class . name , events [ 0 ] . payload [ :store ]
35
35
end
36
36
37
+ def test_fetch_multi_instrumentation_order_of_operations
38
+ operations = [ ]
39
+ callback = -> ( name , *) { operations << name }
40
+
41
+ key_1 = SecureRandom . uuid
42
+ key_2 = SecureRandom . uuid
43
+
44
+ ActiveSupport ::Notifications . subscribed ( callback , /^cache_(read_multi|write_multi)\. active_support$/ ) do
45
+ @cache . fetch_multi ( key_1 , key_2 ) { |key | key * 2 }
46
+ end
47
+
48
+ assert_equal %w[ cache_read_multi.active_support cache_write_multi.active_support ] , operations
49
+ end
50
+
37
51
def test_read_multi_instrumentation
38
52
key_1 = SecureRandom . uuid
39
53
@cache . write ( key_1 , SecureRandom . alphanumeric )
You can’t perform that action at this time.
0 commit comments