class Rack::Cache::Storage
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.
Public Class Methods
instance()
click to toggle source
# File lib/rack/cache/storage.rb, line 57 def self.instance @@singleton_instance end
new()
click to toggle source
# File lib/rack/cache/storage.rb, line 12 def initialize @metastores = {} @entitystores = {} end
Public Instance Methods
clear()
click to toggle source
# File lib/rack/cache/storage.rb, line 25 def clear @metastores.clear @entitystores.clear nil end
resolve_entitystore_uri(uri)
click to toggle source
# File lib/rack/cache/storage.rb, line 21 def resolve_entitystore_uri(uri) @entitystores[uri.to_s] ||= create_store(EntityStore, uri) end
resolve_metastore_uri(uri)
click to toggle source
# File lib/rack/cache/storage.rb, line 17 def resolve_metastore_uri(uri) @metastores[uri.to_s] ||= create_store(MetaStore, uri) end
Private Instance Methods
create_store(type, uri)
click to toggle source
# File lib/rack/cache/storage.rb, line 32 def create_store(type, uri) if uri.respond_to?(:scheme) || uri.respond_to?(:to_str) 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 else # hack in support for passing a Dalli::Client or Memcached object # as the storage URI. case when defined?(::Dalli) && uri.kind_of?(::Dalli::Client) type.const_get(:Dalli).resolve(uri) when defined?(::Memcached) && uri.respond_to?(:stats) type.const_get(:MemCached).resolve(uri) else fail "Unknown storage provider: #{uri.to_s}" end end end