Class: WCC::Data::FaradayClientAppTokenAuth::RedisCache

Inherits:
Object
  • Object
show all
Defined in:
lib/wcc/data/faraday_client_app_token_auth.rb

Constant Summary collapse

DEFAULT_CACHE_KEY =
"org.watermark.data.client-app-token-cache-store"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection, cache_key: DEFAULT_CACHE_KEY) ⇒ RedisCache

Returns a new instance of RedisCache.



7
8
9
10
# File 'lib/wcc/data/faraday_client_app_token_auth.rb', line 7

def initialize(connection, cache_key: DEFAULT_CACHE_KEY)
  @connection = connection
  @cache_key = cache_key
end

Instance Attribute Details

#cache_keyObject (readonly)

Returns the value of attribute cache_key.



5
6
7
# File 'lib/wcc/data/faraday_client_app_token_auth.rb', line 5

def cache_key
  @cache_key
end

#connectionObject (readonly)

Returns the value of attribute connection.



5
6
7
# File 'lib/wcc/data/faraday_client_app_token_auth.rb', line 5

def connection
  @connection
end

Instance Method Details

#[](hostname) ⇒ Object



12
13
14
# File 'lib/wcc/data/faraday_client_app_token_auth.rb', line 12

def [](hostname)
  connection.call { |r| r.hget cache_key, hostname }
end

#[]=(hostname, token) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/wcc/data/faraday_client_app_token_auth.rb', line 16

def []=(hostname, token)
  if token
    connection.call { |r| r.hset cache_key, hostname, token }
  else
    connection.call { |r| r.hdel cache_key, hostname }
  end
end