@@ -52,13 +52,13 @@ class CkbTransaction < ApplicationRecord
5252 after_commit :flush_cache
5353
5454 def self . cached_find ( query_key )
55- Rails . cache . realize ( [ name , query_key ] , race_condition_ttl : 3 . seconds ) do
55+ Rails . cache . realize ( [ name , query_key ] , race_condition_ttl : 3 . seconds , expires_in : 1 . hour ) do
5656 find_by ( tx_hash : query_key )
5757 end
5858 end
5959
6060 def self . largest_in_epoch ( epoch_number )
61- Rails . cache . fetch ( [ "epoch" , epoch_number , "largest_tx" ] ) do
61+ Rails . cache . fetch ( [ "epoch" , epoch_number , "largest_tx" ] , expires_in : 12 . hour ) do
6262 tx = CkbTransaction . where ( block : { epoch_number : } ) . order ( bytes : :desc ) . first
6363 if tx . bytes
6464 {
@@ -77,7 +77,7 @@ def self.write_raw_hash_cache(tx_hash, raw_hash = nil)
7777 raw_hash = tx_hash
7878 tx_hash = raw_hash [ "hash" ]
7979 end
80- Rails . cache . write ( [ name , tx_hash , "raw_hash" ] , raw_hash , expires_in : 1 . day )
80+ Rails . cache . write ( [ name , tx_hash , "raw_hash" ] , raw_hash , expires_in : 10 . minutes )
8181 end
8282
8383 # fetch using rpc method "get_transaction"
@@ -86,7 +86,7 @@ def self.write_raw_hash_cache(tx_hash, raw_hash = nil)
8686 # @param write_raw_hash_cache [Boolean] if we should write raw hash of transaction without status to cache
8787 # @return [Hash]
8888 def self . fetch_raw_hash_with_status ( tx_hash , write_raw_hash_cache : true )
89- Rails . cache . fetch ( [ name , tx_hash , "raw_hash_with_status" ] , expires_in : 1 . day , skip_nil : true ) do
89+ Rails . cache . fetch ( [ name , tx_hash , "raw_hash_with_status" ] , expires_in : 10 . minutes , skip_nil : true ) do
9090 res = CkbSync ::Api . instance . directly_single_call_rpc method : "get_transaction" , params : [ tx_hash ]
9191 h = res [ "result" ] . with_indifferent_access
9292 self . write_raw_hash_cache ( tx_hash , h [ "transaction" ] ) if write_raw_hash_cache
@@ -99,7 +99,7 @@ def self.fetch_raw_hash_with_status(tx_hash, write_raw_hash_cache: true)
9999 # @param tx_hash [String]
100100 # @return [Hash]
101101 def self . fetch_raw_hash ( tx_hash )
102- Rails . cache . fetch ( [ name , tx_hash , "raw_hash" ] , expires_in : 1 . day , skip_nil : true ) do
102+ Rails . cache . fetch ( [ name , tx_hash , "raw_hash" ] , expires_in : 10 . minutes , skip_nil : true ) do
103103 fetch_raw_hash_with_status ( tx_hash , write_raw_hash_cache : false ) [ "transaction" ]
104104 end
105105 end
@@ -108,9 +108,9 @@ def self.fetch_raw_hash(tx_hash)
108108 # @param tx_hash [String]
109109 # @return [CKB::Types::TransactionWithStatus]
110110 def self . fetch_sdk_transaction_with_status ( tx_hash , write_object_cache : true )
111- Rails . cache . fetch ( [ name , tx_hash , "object_with_status" ] , expires_in : 1 . day , skip_nil : true ) do
111+ Rails . cache . fetch ( [ name , tx_hash , "object_with_status" ] , expires_in : 10 . minutes , skip_nil : true ) do
112112 tx = CKB ::Types ::TransactionWithStatus . from_h fetch_raw_hash_with_status ( tx_hash )
113- Rails . cache . write ( [ name , tx_hash , "object" ] , tx . transaction , expires_in : 1 . day ) if write_object_cache
113+ Rails . cache . write ( [ name , tx_hash , "object" ] , tx . transaction , expires_in : 10 . minutes ) if write_object_cache
114114 tx
115115 end
116116 end
@@ -119,13 +119,13 @@ def self.fetch_sdk_transaction_with_status(tx_hash, write_object_cache: true)
119119 # @param tx_hash [String]
120120 # @return [CKB::Types::Transaction]
121121 def self . fetch_sdk_transaction ( tx_hash )
122- Rails . cache . fetch ( [ name , tx_hash , "object" ] , expires_in : 1 . day , skip_nil : true ) do
122+ Rails . cache . fetch ( [ name , tx_hash , "object" ] , expires_in : 10 . minutes , skip_nil : true ) do
123123 sdk_tx_with_status = Rails . cache . read ( [ name , tx_hash , "object_with_status" ] )
124124 if sdk_tx_with_status
125125 return sdk_transaction_with_status . transaction
126126 else
127127 tx = CKB ::Types ::Transaction . from_h fetch_raw_hash ( tx_hash ) . with_indifferent_access
128- Rails . cache . write ( [ name , tx_hash , "object" ] , tx , expires_in : 1 . day )
128+ Rails . cache . write ( [ name , tx_hash , "object" ] , tx , expires_in : 10 . minutes )
129129 tx
130130 end
131131 end
@@ -199,7 +199,7 @@ def detailed_message
199199
200200 # convert current record to raw hash with standard RPC json data structure
201201 def to_raw
202- Rails . cache . fetch ( [ self . class . name , tx_hash , "raw_hash" ] , expires_in : 1 . day ) do
202+ Rails . cache . fetch ( [ self . class . name , tx_hash , "raw_hash" ] , expires_in : 10 . minutes ) do
203203 _outputs = cell_outputs . order ( cell_index : :asc ) . to_a
204204 cell_deps = cell_dependencies . includes ( :cell_output ) . to_a
205205
0 commit comments