Sha256: de092f73490092fb60ff0e4ae6474cb016be7046d7cb16537090748c400ed2f4

Contents?: true

Size: 1.13 KB

Versions: 26

Compression:

Stored size: 1.13 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

    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

26 entries across 26 versions & 5 rubygems

Version Path
rtomayko-rack-cache-0.3.9 lib/rack/cache/storage.rb
rtomayko-rack-cache-0.4 lib/rack/cache/storage.rb
rtomayko-rack-cache-0.5 lib/rack/cache/storage.rb
radiant-1.0.0.rc2 vendor/rack-cache/lib/rack/cache/storage.rb
radiant-1.0.0.rc1 vendor/rack-cache/lib/rack/cache/storage.rb
radiantcms-couchrest_model-0.2.4 vendor/rack-cache/lib/rack/cache/storage.rb
radiantcms-couchrest_model-0.2.2 vendor/rack-cache/lib/rack/cache/storage.rb
radiantcms-couchrest_model-0.2.1 vendor/rack-cache/lib/rack/cache/storage.rb
radiantcms-couchrest_model-0.2 vendor/rack-cache/lib/rack/cache/storage.rb
radiantcms-couchrest_model-0.1.9 vendor/rack-cache/lib/rack/cache/storage.rb
radiantcms-couchrest_model-0.1.8 vendor/rack-cache/lib/rack/cache/storage.rb
radiantcms-couchrest_model-0.1.7 vendor/rack-cache/lib/rack/cache/storage.rb
radiantcms-couchrest_model-0.1.6 vendor/rack-cache/lib/rack/cache/storage.rb
radiantcms-couchrest_model-0.1.5 vendor/rack-cache/lib/rack/cache/storage.rb
radiantcms-couchrest_model-0.1.3 vendor/rack-cache/lib/rack/cache/storage.rb
radiantcms-couchrest_model-0.1.2 vendor/rack-cache/lib/rack/cache/storage.rb
radiantcms-couchrest_model-0.1.1 vendor/rack-cache/lib/rack/cache/storage.rb
radiantcms-couchrest_model-0.1 vendor/rack-cache/lib/rack/cache/storage.rb
radiant-0.9.1 vendor/rack-cache/lib/rack/cache/storage.rb
radiant-0.8.2 vendor/rack-cache/lib/rack/cache/storage.rb