w2v-server: cache classic ca results
diff --git a/w2v-server.pl b/w2v-server.pl
index e04f212..a5ef690 100755
--- a/w2v-server.pl
+++ b/w2v-server.pl
@@ -30,6 +30,7 @@
my $training_args="";
my $mergedEnd=0;
my %cache;
+my %cccache; # classic collocator cache
getopts('d:Gil:p:m:n:M:');
@@ -83,6 +84,16 @@
$c->reply->static($url);
};
+sub getClassicCollocatorsCached {
+ my ($c, $word) = @_;
+ if(!$cccache{$word}) {
+ $cccache{$word} = getClassicCollocators($word);
+ } else {
+ $c->app->log->info("Getting classic collocators for $word from cache.");
+ }
+ return $cccache{$word};
+}
+
post '/derekovecs/getVecsByRanks' => sub {
my $self = shift;
my $vec = getVecs($self->req->json);
@@ -91,12 +102,12 @@
any '*/getClassicCollocators' => sub {
my $self = shift;
- $self->render(data => getClassicCollocators($self->param("w") ? $self->param("w") : $self->req->json), format=>'json');
+ $self->render(data => getClassicCollocatorsCached($self, $self->param("w") ? $self->param("w") : $self->req->json), format=>'json');
};
any '/getClassicCollocators' => sub {
my $self = shift;
- $self->render(data => getClassicCollocators($self->param("w") ? $self->param("w") : $self->req->json), format=>'json');
+ $self->render(data => getClassicCollocatorsCached($self, $self->param("w") ? $self->param("w") : $self->req->json), format=>'json');
};
get '*/img/*' => sub {