Created
April 30, 2010 14:59
-
-
Save soh335/385316 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
use Plack::Request; | |
use LWP::UserAgent; | |
use Cache::FastMmap; | |
my $cache = Cache::FastMmap->new; | |
return sub { | |
my $req = Plack::Request->new(shift); | |
if ( !$cache->get($req->request_uri) ) { | |
my $_req = HTTP::Request->new( | |
$req->method, | |
$req->request_uri, | |
$req->headers, | |
$req->raw_body | |
); | |
my $ua = LWP::UserAgent->new; | |
my $res = $ua->request( $_req ); | |
my @res_header; | |
$res->headers->scan(sub{ push @res_header, @_; }); | |
$cache->set($req->request_uri, [ $res->code, \@res_header, [$res->content] ]); | |
} | |
$cache->get($req->request_uri); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
plackup -p 3000 -s AnyEvent |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment