lib/jwk-loader.rb in jwk-loader-0.1.1 vs lib/jwk-loader.rb in jwk-loader-1.0.0
- old
+ new
@@ -3,11 +3,39 @@
require_relative "jwk_loader/version"
require_relative "jwk_loader/jwks"
require_relative "jwk_loader/jwks_uri_provider"
require_relative "jwk_loader/memory_cache"
require_relative "jwk_loader/error"
+require_relative "jwk_loader/config/config"
module JwkLoader
- def self.for_uri(**options)
- JwksUriProvider.new(**options)
+ class << self
+ def for_uri(**options)
+ options[:cache] ||= config[:cache]
+ options[:cache_grace_period] ||= config[:cache_grace_period]
+ JwksUriProvider.new(**options)
+ end
+
+ def cache
+ config[:cache]
+ end
+
+ def configure
+ yield config
+ end
+
+ def config
+ @config ||= JwkLoader::Config.new.tap do |cfg|
+ cfg[:cache] = MemoryCache.new
+ cfg[:cache_grace_period] = 900
+ end
+ end
+
+ def reset!
+ @config = nil
+ end
+
+ def memory_store
+ @memory_store ||= MemoryCache.new
+ end
end
end