Module: SafeMemoize::PublicMetricsMethods

Included in:
InstanceMethods
Defined in:
lib/safe_memoize/public_metrics_methods.rb

Instance Method Summary collapse

Instance Method Details

#cache_hit_rateObject



25
26
27
# File 'lib/safe_memoize/public_metrics_methods.rb', line 25

def cache_hit_rate
  cache_stats[:hit_rate]
end

#cache_metrics_reset(method_name = nil) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/safe_memoize/public_metrics_methods.rb', line 33

def cache_metrics_reset(method_name = nil)
  with_memo_lock do
    if method_name
      _reset_cache_metrics_for(method_name.to_sym)
    else
      _reset_cache_metrics
    end
  end
end

#cache_miss_rateObject



29
30
31
# File 'lib/safe_memoize/public_metrics_methods.rb', line 29

def cache_miss_rate
  cache_stats[:miss_rate]
end

#cache_statsObject



5
6
7
8
9
10
11
12
# File 'lib/safe_memoize/public_metrics_methods.rb', line 5

def cache_stats
  with_memo_lock do
    metrics = memo_metrics_store
    return empty_stats if metrics.empty?

    aggregate_metrics(metrics, include_method: true)
  end
end

#cache_stats_for(method_name) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/safe_memoize/public_metrics_methods.rb', line 14

def cache_stats_for(method_name)
  method_name = method_name.to_sym

  with_memo_lock do
    metrics = memo_metrics_store.select { |key, _| key[0] == method_name }
    return empty_stats.merge(method: method_name) if metrics.empty?

    aggregate_metrics(metrics, include_method: false).merge(method: method_name)
  end
end