Skip to content

Commit

Permalink
Replace memcached with dalli
Browse files Browse the repository at this point in the history
dalli is a pure ruby library, so this removes the dependency on the libmemcached C library
  • Loading branch information
darkhelmet committed Nov 4, 2012
1 parent d3c1879 commit 4c850e9
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Expand Up @@ -15,7 +15,7 @@ gem 'high_voltage'
gem 'highline'
gem 'jquery-rails'
gem 'mail'
gem 'memcached'
gem 'dalli'
gem 'multi_json'
gem 'paul_revere'
gem 'pg'
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Expand Up @@ -73,6 +73,7 @@ GEM
cucumber (>= 1.1.8)
nokogiri (>= 1.5.0)
daemons (1.1.9)
dalli (2.3.0)
database_cleaner (0.9.1)
delayed_job (3.0.3)
activesupport (~> 3.0)
Expand Down Expand Up @@ -128,7 +129,6 @@ GEM
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
memcached (1.4.6)
method_source (0.8.1)
mime-types (1.19)
multi_json (1.3.7)
Expand Down Expand Up @@ -254,6 +254,7 @@ DEPENDENCIES
clearance
cucumber-rails
daemons
dalli
database_cleaner
delayed_job
delayed_job_active_record
Expand All @@ -270,7 +271,6 @@ DEPENDENCIES
jruby-openssl
launchy
mail
memcached
multi_json
newrelic-redis
newrelic_rpm
Expand Down
22 changes: 12 additions & 10 deletions app/middleware/api_v1_depedencies.rb
@@ -1,11 +1,11 @@
require 'memcached'
require 'dalli'

class V1MarshaledDepedencies

LIMIT = 250

BadRequest = [404, {}, ["Go away"]]
TooMany = [413, {},
TooMany = [413, {},
["Too many gems to resolve, please request less than #{LIMIT}"]]

def data_for(name, ary, cache)
Expand Down Expand Up @@ -34,7 +34,7 @@ def data_for(name, ary, cache)
ary
end

CACHE = Memcached.new("localhost:11211")
CACHE = Dalli::Client.new("localhost:11211")

def call(env)
request = Rack::Request.new(env)
Expand All @@ -55,14 +55,16 @@ def call(env)
gems.each do |g|
begin
data = cache.get "gem.#{g}"
ary += Marshal.load(data)
rescue Memcached::NotFound
begin
data_for g, ary, cache
rescue
return BadRequest
if data
ary += Marshal.load(data)
else
begin
data_for g, ary, cache
rescue
return BadRequest
end
end
rescue Memcached::ServerIsMarkedDead
rescue Dalli::RingError
begin
data_for g, ary, nil
rescue
Expand Down
Binary file added vendor/cache/dalli-2.3.0.gem
Binary file not shown.
Binary file removed vendor/cache/memcached-1.4.6.gem
Binary file not shown.

0 comments on commit 4c850e9

Please sign in to comment.