Skip to content

Commit

Permalink
Fix passing memcache objects in entitystore option
Browse files Browse the repository at this point in the history
  • Loading branch information
rtomayko committed Jun 6, 2009
1 parent 05d2336 commit 12b0de7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
30 changes: 18 additions & 12 deletions lib/rack/cache/entitystore.rb
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions lib/rack/cache/storage.rb
Expand Up @@ -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}"
Expand Down

0 comments on commit 12b0de7

Please sign in to comment.