Module: SqlSafetyNet::CacheStore

Extended by:
ActiveSupport::Concern
Defined in:
lib/sql_safety_net/cache_store.rb

Overview

This module provides a hook into ActiveSupport::Cache::Store caches to keep track of when a query happens inside a cache fetch block. This will be reported in the analysis.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.in_fetch_block?Boolean

Return true if called from within a fetch block.

Returns:

  • (Boolean)


24
25
26
# File 'lib/sql_safety_net/cache_store.rb', line 24

def in_fetch_block?
  !!Thread.current[:sql_safety_net_in_cache_store_fetch_block]
end

Instance Method Details

#fetch_with_sql_safety_net(*args, &block) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/sql_safety_net/cache_store.rb', line 12

def fetch_with_sql_safety_net(*args, &block)
  save_val = Thread.current[:sql_safety_net_in_cache_store_fetch_block]
  begin
    Thread.current[:sql_safety_net_in_cache_store_fetch_block] = true
    fetch_without_sql_safety_net(*args, &block)
  ensure
    Thread.current[:sql_safety_net_in_cache_store_fetch_block] = save_val
  end
end