Index: /trunk/ippScripts/scripts/phase0_exp.pl
===================================================================
--- /trunk/ippScripts/scripts/phase0_exp.pl	(revision 9501)
+++ /trunk/ippScripts/scripts/phase0_exp.pl	(revision 9502)
@@ -4,17 +4,20 @@
 use strict;
 
+use Cache::File;
+use Storable qw( freeze thaw );
+use File::Basename qw( basename );
 use IPC::Cmd qw( can_run run );
 use PS::IPP::Metadata::Config;
 use PS::IPP::Metadata::List qw( parse_md_list );
 use Statistics::Descriptive;
-use Data::Dumper;
 
 use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
 use Pod::Usage qw( pod2usage );
 
-my ($exptag, $no_update);
+my ($cache, $exptag, $no_update);
 
 GetOptions(
-    'exp_tag|e=s'    => \$exptag,
+    'caches'        => \$cache,
+    'exp_tag|e=s'   => \$exptag,
     'no-update'     => \$no_update
 ) or pod2usage( 2 );
@@ -70,4 +73,11 @@
 die "Can't find required tools.\n" if $missing_tools;
 
+# setup cache interface
+
+my $c = Cache::File->new(
+    cache_root => File::Spec->catdir($ENV{'HOME'}, '.', basename($0)),
+    default_expires => '7200 sec',
+);
+
 my $mdcParser = PS::IPP::Metadata::Config->new;        # Parser for metadata config files
 
@@ -77,5 +87,5 @@
     my $command = "$p0tool -rawimfile -exp_tag $exptag";
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-        run(command => $command, verbose => 1);
+        cache_run(command => $command, verbose => 1);
     die "Unable to perform p0tool on exposure id $exptag: $error_code\n" if not $success;
     my $metadata = $mdcParser->parse(join "", @$stdout_buf)
@@ -159,5 +169,5 @@
  
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-        run(command => \@command, verbose => 1);
+        cache_run(command => \@command, verbose => 1);
     die "Unable to run phase0 update for $exptag: $error_code\n" if not $success;
 }
@@ -176,3 +186,22 @@
 }
 
-END { system("sync") == 0 or die "failed to execute sync: $!" }
+sub cache_run
+{
+    my %p = @_;
+
+    my $cmd_output = $c->get($p{command}) if $cache;
+    if (defined $cmd_output) {
+        return @{thaw $cmd_output};
+    } else {
+        my @output = run(%p);
+        $c->set($p{command}, freeze \@output) if $cache;
+        return @output;
+    }
+}
+
+END {
+    my $exit = $?;
+    system("sync") == 0 or die "failed to execute sync: $!";
+    $? = $exit;
+}
+
