Permalink
Browse files

Auto merge of #149 - sonalkr132:new-index-memcache, r=indirect

Use memcache for new index response

I am not sure if this is what was needed in #141 Still, here goes nothing
  • Loading branch information...
2 parents 9b4304e + 61715ce commit 02c2633278edc81bf2e58bf9d7022b8607fd02e5 @homu homu committed Sep 4, 2016
Showing with 24 additions and 3 deletions.
  1. +2 −0 lib/bundler_api/cache.rb
  2. +2 −2 lib/bundler_api/web.rb
  3. +15 −1 spec/cache_spec.rb
  4. +5 −0 spec/update/job_spec.rb
View
2 lib/bundler_api/cache.rb
@@ -77,6 +77,8 @@ def purge_gem(gem_helper)
def purge_memory_cache(name)
memcached_client.delete "deps/v1/#{name}"
+ memcached_client.delete "info/#{name}"
+ memcached_client.delete "names"
end
def cdn_client
View
4 lib/bundler_api/web.rb
@@ -148,7 +148,7 @@ def json_payload(payload)
get "/names" do
status 404 unless NEW_INDEX_ENABLED
etag_response_for("names") do
- CompactIndex.names(@gem_info.names)
+ @dalli_client.fetch('names') { CompactIndex.names(@gem_info.names) }
end
end
@@ -164,7 +164,7 @@ def json_payload(payload)
get "/info/:name" do
status 404 unless NEW_INDEX_ENABLED
etag_response_for(params[:name]) do
- @gem_info.info(params[:name])
+ @dalli_client.fetch("info/#{params[:name]}") { @gem_info.info(params[:name]) }
end
end
View
16 spec/cache_spec.rb
@@ -113,11 +113,25 @@
let(:name) { 'bundler-1.0.0' }
subject { cache.purge_memory_cache(name) }
- it 'purge memcached gem' do
+ it 'purge memcached gem api' do
cache.memcached_client.set("deps/v1/#{name}", "omg!")
expect(cache.memcached_client.get("deps/v1/#{name}")).to_not be_nil
subject
expect(cache.memcached_client.get("deps/v1/#{name}")).to be_nil
end
+
+ it 'purge memcached gem info' do
+ cache.memcached_client.set("info/#{name}", "omg!")
+ expect(cache.memcached_client.get("info/#{name}")).to_not be_nil
+ subject
+ expect(cache.memcached_client.get("info/#{name}")).to be_nil
+ end
+
+ it 'purge memcached gem names' do
+ cache.memcached_client.set("names", "omg!")
+ expect(cache.memcached_client.get("names")).to_not be_nil
+ subject
+ expect(cache.memcached_client.get("names")).to be_nil
+ end
end
end
View
5 spec/update/job_spec.rb
@@ -5,13 +5,16 @@
require 'bundler_api/update/atomic_counter'
require 'bundler_api/update/job'
require 'bundler_api/web'
+require 'bundler_api/cache'
describe BundlerApi::Job do
include Rack::Test::Methods
let(:db) { $db }
let(:builder) { GemBuilder.new(db) }
let(:counter) { BundlerApi::AtomicCounter.new }
let(:mutex) { Mutex.new }
+ let(:client) { double(:client, purge_path: nil, purge_key: nil) }
+ let(:cache) { BundlerApi::CacheInvalidator.new(cdn: client) }
def app
BundlerApi::Web.new($db, $db, silent: true)
@@ -95,6 +98,8 @@ def dependencies(name, version = "1.0", platform = "ruby")
payload = BundlerApi::GemHelper.new("foo1", Gem::Version.new(version), 'ruby')
job = BundlerApi::Job.new(db, payload, mutex, counter, silent: true)
job.run
+ cache.purge_specs
+ cache.purge_memory_cache('foo1')
get '/info/foo1'
last_response.body

0 comments on commit 02c2633

Please sign in to comment.