Class: RedisRevocationCache

Inherits:
Object
  • Object
show all
Defined in:
lib/sslackey/cache/redis_revocation_cache.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(redis_host, redis_port) ⇒ RedisRevocationCache

Returns a new instance of RedisRevocationCache.



9
10
11
12
# File 'lib/sslackey/cache/redis_revocation_cache.rb', line 9

def initialize(redis_host, redis_port)
  @redis = Redis::Namespace.new(:revocation, :redis => Redis.new(:host => redis_host, :port => redis_port, :threadsafe => true))
  @expiration_seconds = 3600
end

Instance Attribute Details

#expiration_secondsObject

Returns the value of attribute expiration_seconds.



7
8
9
# File 'lib/sslackey/cache/redis_revocation_cache.rb', line 7

def expiration_seconds
  @expiration_seconds
end

#redisObject

Returns the value of attribute redis.



7
8
9
# File 'lib/sslackey/cache/redis_revocation_cache.rb', line 7

def redis
  @redis
end

Instance Method Details

#cache_response(certificate, response) ⇒ Object



20
21
22
23
24
25
# File 'lib/sslackey/cache/redis_revocation_cache.rb', line 20

def cache_response(certificate, response)
  key = get_key(certificate)
  LOGGER.info "caching revocation response for certificate: #{certificate.subject}" if defined?(LOGGER)
  redis.set(key, response)
  redis.expire(key, expiration_seconds)
end

#cached_response(certificate) ⇒ Object



14
15
16
17
18
# File 'lib/sslackey/cache/redis_revocation_cache.rb', line 14

def cached_response(certificate)
  response = redis.get(get_key(certificate))
  LOGGER.info("got a cached response: #{response}") if response && defined?(LOGGER)
  response.try(:to_sym)
end

#get_key(certificate) ⇒ Object



27
28
29
# File 'lib/sslackey/cache/redis_revocation_cache.rb', line 27

def get_key(certificate)
  certificate.subject.hash
end