Class: RedisRevocationCache
- Inherits:
-
Object
- Object
- RedisRevocationCache
- Defined in:
- lib/sslackey/cache/redis_revocation_cache.rb
Instance Attribute Summary collapse
-
#expiration_seconds ⇒ Object
Returns the value of attribute expiration_seconds.
-
#redis ⇒ Object
Returns the value of attribute redis.
Instance Method Summary collapse
- #cache_response(certificate, response) ⇒ Object
- #cached_response(certificate) ⇒ Object
- #get_key(certificate) ⇒ Object
-
#initialize(redis_host, redis_port) ⇒ RedisRevocationCache
constructor
A new instance of RedisRevocationCache.
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_seconds ⇒ Object
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 |
#redis ⇒ Object
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 |