flyerhzm/jruby-memcached — pull request #5 by robmack (2013-12-13 20:58:06+00:00)
Title: Return nil on cache miss instead of throwing exception

Thanks for your work on jruby-memcached. We recently used it on a project and it was faster than our previous solution.

I was curious if you had any feedback on this changeset. If you like the general approach and want to merge it, I can clean it up and resubmit it to you.

When profiling our application, we noticed a lot of time spent in exception handling coming from exceptions raised by jruby-memcached on cache misses.

We modify the `get` method to return a nil if the item doesn't exist in the cache instead of raising an exception. This improved the speed for us.

This is the benchmark we used:

````ruby
Rails.cache.clear
Benchmark.bm(30) do |bm|
bm.report("get with cache miss") do
100000.times {|i| Rails.cache.get "foo#{i}" }
end
end
````

Running this from the console of our Rails app against version 0.5.5:

````
user system total real
get with cache miss 96.390000 5.200000 101.590000 (103.743000)
=> [ 96.390000 5.200000 101.590000 (103.743000)
]
````

With the patch:

````
user system total real
get with cache miss 4.460000 3.590000 8.050000 ( 8.541000)
=> [ 4.460000 3.590000 8.050000 ( 8.541000)
]
````

Thanks,

Rob Mack