Skip to content
This repository has been archived by the owner on Dec 5, 2023. It is now read-only.

Commit

Permalink
replace dalli response cache with rack-cache cache_control
Browse files Browse the repository at this point in the history
  • Loading branch information
Zachary Scott committed Sep 26, 2011
1 parent 7fdbdbb commit 8a75dce
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 37 deletions.
3 changes: 1 addition & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ gem "crack"
gem "httparty"
gem "sinatra"
gem "rdiscount"
gem "dalli"
gem "rack"
gem "rack-cache"
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ GEM
remote: http://rubygems.org/
specs:
crack (0.1.8)
dalli (1.0.2)
haml (3.0.25)
httparty (0.7.3)
crack (= 0.1.8)
rack (1.2.1)
rack-cache (1.1)
rack (>= 0.4)
rdiscount (1.6.8)
sinatra (1.1.2)
rack (~> 1.1)
Expand All @@ -18,9 +19,8 @@ PLATFORMS

DEPENDENCIES
crack
dalli
haml
httparty
rack
rack-cache
rdiscount
sinatra
54 changes: 22 additions & 32 deletions blarghhhh.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,39 @@
require "httparty"
require "sinatra"
require "rdiscount"
require "dalli"

set :base_uri, 'http://github.com/api/v2/json'
set :userid, 'zzak'
set :repoid, 'blog.zacharyscott.net'
#set :userid, ENV['GITHUB_USER']
#set :repoid, ENV['GITHUB_REPO']
set :userid, ENV['GITHUB_USER']
set :repoid, ENV['GITHUB_REPO']
set :public, File.dirname(__FILE__) + '/public'
set :cache, Dalli::Client.new(
ENV['MEMCACHE_SERVERS'],
:username => ENV['MEMCACHE_USERNAME'],
:password => ENV['MEMCACHE_PASSWORD'],
:expires_in => 300)

set :views, File.dirname(__FILE__)

get '/' do
@info = settings.cache.fetch("info") do
HTTParty.get("#{settings.base_uri}/repos/show/#{settings.userid}/#{settings.repoid}")
end
@user = settings.cache.fetch("user") do
HTTParty.get("#{settings.base_uri}/user/show/#{settings.userid}")
end
@blobs = settings.cache.fetch("blobs") do
HTTParty.get("#{settings.base_uri}/blob/all/#{settings.userid}/#{settings.repoid}/master")
configure :production do
sha1, date = `git log HEAD~1..HEAD --pretty=format:%h^%ci`.strip.split('^')

require 'rack/cache'
use Rack::Cache

before do
cache_control :public, :must_revalidate, :max_age=>300
etag sha1
last_modified date
end
end

get '/' do
@info = HTTParty.get("#{settings.base_uri}/repos/show/#{settings.userid}/#{settings.repoid}")
@user = HTTParty.get("#{settings.base_uri}/user/show/#{settings.userid}")
@blobs = HTTParty.get("#{settings.base_uri}/blob/all/#{settings.userid}/#{settings.repoid}/master")
haml :index
end

get '/show/:post/:sha' do
@info = settings.cache.fetch("info") do
HTTParty.get("#{settings.base_uri}/repos/show/#{settings.userid}/#{settings.repoid}")
end
@user = settings.cache.fetch("user") do
HTTParty.get("#{settings.base_uri}/user/show/#{settings.userid}")
end
markdown = settings.cache.fetch("#{params[:sha]}") do
HTTParty.get("#{settings.base_uri}/blob/show/#{settings.userid}/#{settings.repoid}/#{params[:sha]}").to_s
end
@info = HTTParty.get("#{settings.base_uri}/repos/show/#{settings.userid}/#{settings.repoid}")
@user = HTTParty.get("#{settings.base_uri}/user/show/#{settings.userid}")
markdown = HTTParty.get("#{settings.base_uri}/blob/show/#{settings.userid}/#{settings.repoid}/#{params[:sha]}").to_s
@post = RDiscount.new(markdown).to_html
@history = settings.cache.fetch("#{params[:sha]}-history") do
HTTParty.get("#{settings.base_uri}/commits/list/#{settings.userid}/#{settings.repoid}/master/#{params[:post]}").to_hash
end
@history = HTTParty.get("#{settings.base_uri}/commits/list/#{settings.userid}/#{settings.repoid}/master/#{params[:post]}").to_hash
haml :show
end

Expand Down

0 comments on commit 8a75dce

Please sign in to comment.