$self->render( $self->stash('template') , lang => $self->stash('lang') );
};
+get '/lang/:lang/template/*template' => sub { # angular-ui templates
+ my $self = shift;
+ my $path = '/template/' . $self->stash('template');
+ warn "# render_static $path";
+ $self->render_static( $path );
+};
get '/data/' => sub {
my $self = shift;
# CouchDB proxy for _design _view
+our $view_cache;
+
get '/:database/_design/:design/_view/:view' => sub {
my $self = shift;
my $format = $self->param('format');
if ( my $param = $self->req->url->query->clone->remove('callback')->remove('format')->to_string ) {
$url .= '?' . $param
}
+
+ if ( exists $view_cache->{$url}->{time} ) {
+ if ( time() - $view_cache->{$url}->{time} < 60 ) {
+ warn "HIT CouchDB cache $url";
+ $view_cache->{$url}->{hit}++;
+ return _render_jsonp( $self, $view_cache->{$url}->{json} );
+ } else {
+ warn "REFRESH CouchDB cache $url";
+ $view_cache->{$url}->{refresh}++;
+ }
+ } else {
+ $view_cache->{$url}->{miss}++;
+ }
warn "CouchDB proxy $url";
my $json = _couchdb_get($url);
if ( $format eq 'key_array' ) { # array of keys sorted by value
$json->{rows} = [ map { $_->{key} } sort { $b->{value} <=> $a->{value} } @{ $json->{rows} } ];
}
+
+ $view_cache->{$url}->{time} = time();
+ $view_cache->{$url}->{json} = $json;
+
+ warn "# view_cache ",dump($view_cache);
+
_render_jsonp( $self, $json );
};