Sha256: f80064f134172020bf4e71b7f46b3d4eba353f021d614e67337a74d38d3e8bb8
Contents?: true
Size: 1.16 KB
Versions: 4
Compression:
Stored size: 1.16 KB
Contents
require 'uri' require 'rack/cache/metastore' require 'rack/cache/entitystore' module Rack::Cache # Maintains a collection of MetaStore and EntityStore instances keyed by # URI. A single instance of this class can be used across a single process # to ensure that only a single instance of a backing store is created per # unique storage URI. class Storage def initialize @metastores = {} @entitystores = {} end def resolve_metastore_uri(uri) @metastores[uri.to_s] ||= create_store(MetaStore, uri) end def resolve_entitystore_uri(uri) @entitystores[uri.to_s] ||= create_store(EntityStore, uri) end # Clear store instances. def clear @metastores.clear @entitystores.clear nil end private def create_store(type, uri) uri = URI.parse(uri) unless uri.respond_to?(:scheme) if type.const_defined?(uri.scheme.upcase) klass = type.const_get(uri.scheme.upcase) klass.resolve(uri) else fail "Unknown storage provider: #{uri.to_s}" end end public @@singleton_instance = new def self.instance @@singleton_instance end end end
Version data entries
4 entries across 4 versions & 2 rubygems