Skip to content

Commit

Permalink
updated caching to use master function in resource.pm
Browse files Browse the repository at this point in the history
  • Loading branch information
Travis Harrison committed Jan 15, 2013
1 parent 773dce9 commit fb4060b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 25 deletions.
13 changes: 4 additions & 9 deletions src/MGRAST/lib/resources2/matrix.pm
Expand Up @@ -226,14 +226,9 @@ sub instance {
$self->return_data( {"ERROR" => "no valid ids submitted and/or found: ".join(", ", @ids)}, 401 );
}

# get cached if exists
my $cached = $self->memd->get($self->url_id);
if ($cached) {
# do a runaround on ->return_data
print $self->header;
print $cached;
exit 0;
}
# return cached if exists
$self->return_cached();

# prepare data
my $data = $self->prepare_data([keys %$mgids], $type);
$self->return_data($data, undef, 1); # cache this!
Expand All @@ -257,7 +252,7 @@ sub prepare_data {
my $leaf_node = 0;
my $matrix_id = join("_", sort @$data).'_'.join("_", ($type, $glvl, $source, $rtype, $eval, $ident, $alen));
if (@filter > 0) {
$matrix_id .= join("_", sort map { $_ =~ s/\s+/_/ } @filter)."_".$fsrc;
$matrix_id .= join("_", sort map { $_ =~ s/\s+/_/g } @filter)."_".$fsrc;
}

# initialize analysis obj with mgids
Expand Down
11 changes: 3 additions & 8 deletions src/MGRAST/lib/resources2/metagenome.pm
Expand Up @@ -123,14 +123,9 @@ sub instance {
$self->return_data( {"ERROR" => "insufficient permissions to view this data"}, 401 );
}

# get cached if exists
my $cached = $self->memd->get($self->url_id);
if ($cached) {
# do a runaround on ->return_data
print $self->header;
print $cached;
exit 0;
}
# return cached if exists
$self->return_cached();

# prepare data
my $data = $self->prepare_data( [$job] );
$data = $data->[0];
Expand Down
11 changes: 3 additions & 8 deletions src/MGRAST/lib/resources2/project.pm
Expand Up @@ -117,14 +117,9 @@ sub instance {
$self->return_data( {"ERROR" => "insufficient permissions to view this data"}, 401 );
}

# get cached if exists
my $cached = $self->memd->get($self->url_id);
if ($cached) {
# do a runaround on ->return_data
print $self->header;
print $cached;
exit 0;
}
# return cached if exists
$self->return_cached();

# prepare data
my $data = $self->prepare_data( [$project] );
$data = $data->[0];
Expand Down
21 changes: 21 additions & 0 deletions src/MGRAST/lib/resources2/resource.pm
Expand Up @@ -235,6 +235,19 @@ sub check_pagination {
}
}

# return cached data if exists
sub return_cached {
my ($self) = @_;

my $cached = $self->memd->get($self->url_id);
if ($cached) {
# do a runaround on ->return_data
print $self->header;
print $cached;
exit 0;
}
}

# print the actual data output
sub return_data {
my ($self, $data, $error, $cache_me) = @_;
Expand Down Expand Up @@ -468,6 +481,14 @@ sub get_shock_query {
}
}

# I can't find a perl library that gives me random UUID !
sub uuidv4 {
my ($self) = @_;
my $uuid = `python -c "import uuid; print uuid.uuid4()"`;
chomp $uuid;
return $uuid;
}

sub toFloat {
my ($self, $x) = @_;
return $x * 1.0;
Expand Down

0 comments on commit fb4060b

Please sign in to comment.