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 60 def self.instance 61 @@singleton_instance 62 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, options = {})
click to toggle source
# File lib/rack/cache/storage.rb 21 def resolve_entitystore_uri(uri, options = {}) 22 @entitystores[uri.to_s] ||= create_store(EntityStore, uri, options) 23 end
resolve_metastore_uri(uri, options = {})
click to toggle source
# File lib/rack/cache/storage.rb 17 def resolve_metastore_uri(uri, options = {}) 18 @metastores[uri.to_s] ||= create_store(MetaStore, uri, options) 19 end
Private Instance Methods
create_store(type, uri, options = {})
click to toggle source
# File lib/rack/cache/storage.rb 33 def create_store(type, uri, options = {}) 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 return klass.resolve(uri) if klass.method(:resolve).arity == 1 39 klass.resolve(uri, options) 40 else 41 fail "Unknown storage provider: #{uri.to_s}" 42 end 43 else 44 # hack in support for passing a Dalli::Client or Memcached object 45 # as the storage URI. 46 case 47 when defined?(::Dalli) && uri.kind_of?(::Dalli::Client) 48 type.const_get(:Dalli).resolve(uri) 49 when defined?(::Memcached) && uri.respond_to?(:stats) 50 type.const_get(:MemCached).resolve(uri) 51 else 52 fail "Unknown storage provider: #{uri.to_s}" 53 end 54 end 55 end