Browse files

Fix passing memcache objects in entitystore option

  • Loading branch information...
1 parent 05d2336 commit 12b0de7eaa4801c97a57e6fb3c4bcf2d84056f64 @rtomayko rtomayko committed Jun 6, 2009
Showing with 20 additions and 14 deletions.
  1. +18 −12 lib/rack/cache/entitystore.rb
  2. +2 −2 lib/rack/cache/storage.rb
View
30 lib/rack/cache/entitystore.rb
@@ -182,19 +182,25 @@ def open(key)
end
def self.resolve(uri)
- server = "#{uri.host}:#{uri.port || '11211'}"
- options = parse_query(uri.query)
- options.keys.each do |key|
- value =
- case value = options.delete(key)
- when 'true' ; true
- when 'false' ; false
- else value.to_sym
- end
- options[k.to_sym] = value
+ if uri.respond_to?(:scheme)
+ server = "#{uri.host}:#{uri.port || '11211'}"
+ options = parse_query(uri.query)
+ options.keys.each do |key|
+ value =
+ case value = options.delete(key)
+ when 'true' ; true
+ when 'false' ; false
+ else value.to_sym
+ end
+ options[k.to_sym] = value
+ end
+ options[:namespace] = uri.path.sub(/^\//, '')
+ new server, options
+ else
+ # if the object provided is not a URI, pass it straight through
+ # to the underlying implementation.
+ new uri
end
- options[:namespace] = uri.path.sub(/^\//, '')
- new server, options
end
end
View
4 lib/rack/cache/storage.rb
@@ -42,9 +42,9 @@ def create_store(type, uri)
# hack in support for passing a MemCache or Memcached object
# as the storage URI.
case
- when defined?(::MemCache) && type.kind_of?(::MemCache)
+ when defined?(::MemCache) && uri.kind_of?(::MemCache)
type.const_get(:MemCache).resolve(uri)
- when defined?(::Memcached) && type.respond_to?(:stats)
+ when defined?(::Memcached) && uri.respond_to?(:stats)
type.const_get(:MemCached).resolve(uri)
else
fail "Unknown storage provider: #{uri.to_s}"

0 comments on commit 12b0de7

Please sign in to comment.