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.



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

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.



15
16
17
# File 'lib/wcc/data/faraday_client_app_token_auth.rb', line 15

def cache_key
  @cache_key
end

#connectionObject (readonly)

Returns the value of attribute connection.



15
16
17
# File 'lib/wcc/data/faraday_client_app_token_auth.rb', line 15

def connection
  @connection
end

Instance Method Details

#[](hostname) ⇒ Object



22
23
24
# File 'lib/wcc/data/faraday_client_app_token_auth.rb', line 22

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

#[]=(hostname, token) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/wcc/data/faraday_client_app_token_auth.rb', line 26

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