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 59 def self.instance 60 @@singleton_instance 61 end
new()
click to toggle source
# File lib/rack/cache/storage.rb 12 def initialize 13 @metastores = {} 14 @entitystores = {} 15 end
Public Instance Methods
clear()
click to toggle source
# File lib/rack/cache/storage.rb 25 def clear 26 @metastores.clear 27 @entitystores.clear 28 nil 29 end
resolve_entitystore_uri(uri)
click to toggle source
# File lib/rack/cache/storage.rb 21 def resolve_entitystore_uri(uri) 22 @entitystores[uri.to_s] ||= create_store(EntityStore, uri) 23 end
resolve_metastore_uri(uri)
click to toggle source
# File lib/rack/cache/storage.rb 17 def resolve_metastore_uri(uri) 18 @metastores[uri.to_s] ||= create_store(MetaStore, uri) 19 end
Private Instance Methods
create_store(type, uri)
click to toggle source
# File lib/rack/cache/storage.rb 33 def create_store(type, uri) 34 if uri.respond_to?(:scheme) || uri.respond_to?(:to_str) 35 uri = URI.parse(uri) unless uri.respond_to?(:scheme) 36 if type.const_defined?(uri.scheme.upcase) 37 klass = type.const_get(uri.scheme.upcase) 38 klass.resolve(uri) 39 else 40 fail "Unknown storage provider: #{uri.to_s}" 41 end 42 else 43 # hack in support for passing a Dalli::Client or Memcached object 44 # as the storage URI. 45 case 46 when defined?(::Dalli) && uri.kind_of?(::Dalli::Client) 47 type.const_get(:Dalli).resolve(uri) 48 when defined?(::Memcached) && uri.respond_to?(:stats) 49 type.const_get(:MemCached).resolve(uri) 50 else 51 fail "Unknown storage provider: #{uri.to_s}" 52 end 53 end 54 end