Drop caching

This commit is contained in:
Hakan Ensari 2017-01-10 12:21:19 +00:00
parent 11f3ddb0e4
commit e5cb17d0b9
8 changed files with 2 additions and 40 deletions

View File

@ -2,6 +2,4 @@ before_script:
- psql -c 'create database fixer_test;' -U postgres - psql -c 'create database fixer_test;' -U postgres
rvm: rvm:
- 2.4.0 - 2.4.0
services:
- memcached
sudo: false sudo: false

View File

@ -6,4 +6,4 @@ ADD Gemfile /app/Gemfile
ADD Gemfile.lock /app/Gemfile.lock ADD Gemfile.lock /app/Gemfile.lock
RUN bundle install --without development test RUN bundle install --without development test
ADD . /app ADD . /app
CMD ./wait-for-it.sh db:5432 -s -- wait-for-it.sh memcache:11211 -s -- unicorn -c /app/config/unicorn.rb CMD ./wait-for-it.sh db:5432 -s -- unicorn -c /app/config/unicorn.rb

View File

@ -3,12 +3,10 @@ source 'http://rubygems.org'
ruby '2.4.0' ruby '2.4.0'
gem 'dalli'
gem 'fixer' gem 'fixer'
gem 'kgio' gem 'kgio'
gem 'newrelic_rpm' gem 'newrelic_rpm'
gem 'oj' gem 'oj'
gem 'rack-cache'
gem 'rack-cors' gem 'rack-cors'
gem 'rake' gem 'rake'
gem 'sequel_pg' gem 'sequel_pg'

View File

@ -3,7 +3,6 @@ GEM
specs: specs:
ast (2.3.0) ast (2.3.0)
coderay (1.1.1) coderay (1.1.1)
dalli (2.7.6)
fixer (0.7.0) fixer (0.7.0)
kgio (2.11.0) kgio (2.11.0)
method_source (0.8.2) method_source (0.8.2)
@ -21,8 +20,6 @@ GEM
method_source (~> 0.8.1) method_source (~> 0.8.1)
slop (~> 3.4) slop (~> 3.4)
rack (1.6.5) rack (1.6.5)
rack-cache (1.6.1)
rack (>= 0.4)
rack-cors (0.4.0) rack-cors (0.4.0)
rack-protection (1.5.3) rack-protection (1.5.3)
rack rack
@ -59,7 +56,6 @@ PLATFORMS
ruby ruby
DEPENDENCIES DEPENDENCIES
dalli
fixer fixer
kgio kgio
minitest minitest
@ -67,7 +63,6 @@ DEPENDENCIES
newrelic_rpm newrelic_rpm
oj oj
pry pry
rack-cache
rack-cors rack-cors
rack-test rack-test
rake rake

View File

@ -2,8 +2,6 @@ version: '2'
services: services:
db: db:
image: postgres image: postgres
memcache:
image: memcached
web: web:
build: . build: .
volumes: volumes:
@ -13,7 +11,5 @@ services:
environment: environment:
RACK_ENV: production RACK_ENV: production
DATABASE_URL: postgres://postgres@db/postgres DATABASE_URL: postgres://postgres@db/postgres
MEMCACHE_SERVERS: memcache
links: links:
- db - db
- memcache

View File

@ -1,16 +1,9 @@
# frozen_string_literal: true # frozen_string_literal: true
require 'dalli'
require 'oj' require 'oj'
require 'sinatra' require 'sinatra'
require 'rack/cache'
require 'rack/cors' require 'rack/cors'
require 'quote' require 'quote'
use Rack::Cache,
verbose: true,
metastore: "memcached://#{ENV['MEMCACHE_SERVERS']}/meta",
entitystore: "memcached://#{ENV['MEMCACHE_SERVERS']}/body"
use Rack::Cors do use Rack::Cors do
allow do allow do
origins '*' origins '*'
@ -34,14 +27,11 @@ helpers do
def quote_attributes def quote_attributes
@quote_attributes ||= quote.attributes.tap do |data| @quote_attributes ||= quote.attributes.tap do |data|
symbols = params.values_at('symbols', 'to').compact.first
data[:rates].keep_if { |k, _| symbols.include?(k) } if symbols data[:rates].keep_if { |k, _| symbols.include?(k) } if symbols
end end
end end
def symbols
@symbols ||= params.values_at('symbols', 'to').compact.first
end
def jsonp(data) def jsonp(data)
json = encode_json(data) json = encode_json(data)
callback = params.delete('callback') callback = params.delete('callback')

View File

@ -10,10 +10,6 @@ describe 'the API' do
let(:json) { Oj.load(last_response.body) } let(:json) { Oj.load(last_response.body) }
let(:headers) { last_response.headers } let(:headers) { last_response.headers }
before do
Dalli::Client.new.flush
end
it 'describes itself' do it 'describes itself' do
get '/' get '/'
last_response.must_be :ok? last_response.must_be :ok?
@ -101,11 +97,4 @@ describe 'the API' do
get '/latest?from=GBP&to=USD&amount=100' get '/latest?from=GBP&to=USD&amount=100'
json['rates']['USD'].must_be :>, 100 json['rates']['USD'].must_be :>, 100
end end
it 'sets Content-Type header to JSON when caching' do
2.times do
get '/latest'
last_response.headers['Content-Type'].must_equal 'application/json'
end
end
end end

View File

@ -9,10 +9,6 @@ describe 'the API' do
let(:app) { Sinatra::Application } let(:app) { Sinatra::Application }
let(:json) { Oj.load(last_response.body) } let(:json) { Oj.load(last_response.body) }
before do
Dalli::Client.new.flush
end
it 'handles unfound pages' do it 'handles unfound pages' do
get '/foo' get '/foo'
last_response.status.must_equal 404 last_response.status.must_equal 404