Skip to content

Instantly share code, notes, and snippets.

@soh335
Created May 5, 2010 05:29
Show Gist options
  • Save soh335/390416 to your computer and use it in GitHub Desktop.
Save soh335/390416 to your computer and use it in GitHub Desktop.
use strict;
use warnings;
use Plack::Request;
use Plack::App::File;
use Plack::App::Proxy;
use File::Basename;
use Path::Class qw/dir/;
my %cache;
my $proxy = Plack::App::Proxy->new->to_app;
return sub {
my $env = shift;
my $req = Plack::Request->new($env);
my $res;
if ( !defined($cache{$req->request_uri}) ) {
my $file_path = dir('.', basename($req->path_info) )->absolute->stringify;
if ( -f $file_path ) {
$res = Plack::App::File->new( file => $file_path )->call($env);
}
else
{
$env->{'plack.proxy.url'} = $req->request_uri;
$res = $proxy->($env);
}
$cache{$req->request_uri} = $res;
}
$cache{$req->request_uri};
};
plackup cache.psgi -p 3000 -s Coro
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment