Module: Legion::Extensions::MicrosoftTeams::Helpers::GraphCache

Includes:
Cache::Helper
Included in:
Runners::ApiIngest, Runners::ProfileIngest
Defined in:
lib/legion/extensions/microsoft_teams/helpers/graph_cache.rb

Instance Method Summary collapse

Instance Method Details

#cached_graph_get(conn:, path:, params: {}, ttl: nil, shared: false) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/legion/extensions/microsoft_teams/helpers/graph_cache.rb', line 15

def cached_graph_get(conn:, path:, params: {}, ttl: nil, shared: false)
  effective_ttl = ttl || graph_cache_ttl
  key = graph_cache_key(path: path, params: params, shared: shared)

  cache_fetch(key, ttl: effective_ttl) do
    resp = conn.get(path, params)
    resp.body
  end
rescue StandardError => e
  handle_exception(e, level: :debug, operation: 'GraphCache#cached_graph_get', path: path)
  conn.get(path, params).body
end

#graph_cache_ttlObject



10
11
12
13
# File 'lib/legion/extensions/microsoft_teams/helpers/graph_cache.rb', line 10

def graph_cache_ttl
  settings = teams_extension_settings
  settings.dig(:cache, :graph_ttl) || 300
end

#graph_user_keyObject



28
29
30
31
32
# File 'lib/legion/extensions/microsoft_teams/helpers/graph_cache.rb', line 28

def graph_user_key
  return @graph_user_key if defined?(@graph_user_key)

  @graph_user_key = (Legion::Identity::Process.id if defined?(Legion::Identity::Process) && Legion::Identity::Process.resolved?)
end

#invalidate_graph_cache(path:, params: {}, shared: false) ⇒ Object



34
35
36
37
38
39
# File 'lib/legion/extensions/microsoft_teams/helpers/graph_cache.rb', line 34

def invalidate_graph_cache(path:, params: {}, shared: false)
  key = graph_cache_key(path: path, params: params, shared: shared)
  cache_delete(key)
rescue StandardError => e
  handle_exception(e, level: :debug, operation: 'GraphCache#invalidate_graph_cache')
end