Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Reraise unexpected exceptions and implement read_multi

  • Loading branch information...
commit 829b003132ddd2f45d6bdb0ec5d6e865d19396a4 1 parent 1ff0135
Tim Haines authored
64 Gemfile.lock
View
@@ -0,0 +1,64 @@
+PATH
+ remote: .
+ specs:
+ libmemcached_store (0.4)
+ i18n (~> 0.6)
+ memcached
+
+GEM
+ remote: http://rubygems.org/
+ specs:
+ actionpack (3.2.1)
+ activemodel (= 3.2.1)
+ activesupport (= 3.2.1)
+ builder (~> 3.0.0)
+ erubis (~> 2.7.0)
+ journey (~> 1.0.1)
+ rack (~> 1.4.0)
+ rack-cache (~> 1.1)
+ rack-test (~> 0.6.1)
+ sprockets (~> 2.1.2)
+ activemodel (3.2.1)
+ activesupport (= 3.2.1)
+ builder (~> 3.0.0)
+ activesupport (3.2.1)
+ i18n (~> 0.6)
+ multi_json (~> 1.0)
+ builder (3.0.0)
+ erubis (2.7.0)
+ hike (1.2.1)
+ i18n (0.6.0)
+ journey (1.0.3)
+ json (1.6.5)
+ memcached (1.4.1)
+ metaclass (0.0.1)
+ minitest (2.11.2)
+ mocha (0.10.4)
+ metaclass (~> 0.0.1)
+ multi_json (1.1.0)
+ rack (1.4.1)
+ rack-cache (1.1)
+ rack (>= 0.4)
+ rack-test (0.6.1)
+ rack (>= 1.0)
+ rake (0.9.2.2)
+ rdoc (3.12)
+ json (~> 1.4)
+ sprockets (2.1.2)
+ hike (~> 1.2)
+ rack (~> 1.0)
+ tilt (~> 1.1, != 1.3.0)
+ tilt (1.3.3)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ actionpack (~> 3.2)
+ activesupport (~> 3.2)
+ libmemcached_store!
+ minitest
+ mocha
+ rack
+ rake
+ rdoc
32 lib/active_support/cache/libmemcached_store.rb
View
@@ -33,14 +33,14 @@ def increment(key, amount = 1, options = nil)
log 'incrementing', key, amount
@cache.incr(key, amount)
rescue Memcached::Error
- nil
+ raise
end
def decrement(key, amount = 1, options = nil)
log 'decrementing', key, amount
@cache.decr(key, amount)
rescue Memcached::Error
- nil
+ raise
end
def clear
@@ -51,28 +51,46 @@ def stats
@cache.stats
end
+ def read_multi(*names)
+ # Rails.logger.info "getting names #{names}"
+ options = names.extract_options!
+ options = merged_options(options)
+ values = @cache.get(names)
+ return nil if values.nil?
+ results = {}
+ values.each do |k, v|
+ entry = deserialize_entry(v)
+ results[k] = entry.value
+ end
+ return results
+ rescue Memcached::Error => e
+ log_error(e)
+ raise
+ end
+
+
protected
def read_entry(key, options = nil)
- deserialize_entry(@cache.get(key, false))
+ deserialize_entry(@cache.get(key, false))
rescue Memcached::NotFound
nil
rescue Memcached::Error => e
log_error(e)
- nil
+ raise
end
+
# Set the key to the given value. Pass :unless_exist => true if you want to
# skip setting a key that already exists.
def write_entry(key, entry, options = nil)
method = (options && options[:unless_exist]) ? :add : :set
value = options[:raw] ? entry.value.to_s : entry
-
@cache.send(method, key, value, expires_in(options), marshal?(options))
true
rescue Memcached::Error => e
log_error(e)
- false
+ raise
end
def delete_entry(key, options = nil)
@@ -80,7 +98,7 @@ def delete_entry(key, options = nil)
true
rescue Memcached::Error => e
log_error(e)
- false
+ raise
end
private
2  libmemcached_store.gemspec
View
@@ -25,6 +25,8 @@ Gem::Specification.new do |s|
s.add_development_dependency('rack')
s.add_development_dependency('rake')
s.add_development_dependency('mocha')
+ s.add_development_dependency('rdoc')
+ s.add_development_dependency('minitest')
s.add_development_dependency('activesupport', '~> 3.2')
s.add_development_dependency('actionpack', '~> 3.2')
end
8 test/active_support/libmemcached_store_test.rb
View
@@ -22,6 +22,14 @@ def test_should_overwrite
assert_equal 'baz', @cache.read('foo')
end
+ #Memcached connection dies if you try to read a key with length > 250
+ def test_should_raise_an_exception_if_the_key_is_too_long
+ lk = "a"*1000
+ assert_raises(Memcached::NotStored) {
+ @cache.read(lk)
+ }
+ end
+
def test_fetch_without_cache_miss
@cache.write('foo', 'bar')
@cache.expects(:write).never
Please sign in to comment.
Something went wrong with that request. Please try again.