Index: /trunk/ippScripts/scripts/phase0_imfile.pl
===================================================================
--- /trunk/ippScripts/scripts/phase0_imfile.pl	(revision 9500)
+++ /trunk/ippScripts/scripts/phase0_imfile.pl	(revision 9501)
@@ -7,9 +7,10 @@
 $VERSION = '0.01';
 
+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::Stats;
-use Storabe qw( freeze thaw );
-use Data::Dumper;
 
 use PS::IPP::Config;
@@ -20,8 +21,9 @@
 use Pod::Usage qw( pod2usage );
 
-my ($exp_tag, $class_id, $uri, $no_update);
+my ($cache, $exp_tag, $class_id, $uri, $no_update);
 
 GetOptions(
-    'exp_tag|e=s'    => \$exp_tag,
+    'caches'        => \$cache,
+    'exp_tag|e=s'   => \$exp_tag,
     'class_id|i=s'  => \$class_id,
     'uri|u=s'       => \$uri,
@@ -75,4 +77,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'}, '.pxtools', basename($0)),
+    default_expires => '7200 sec',
+);
+
 # Resolve the input URI
 $uri = File::Spec->rel2abs( $uri, $ipprc->workdir() );
@@ -83,6 +92,7 @@
     my $command = "$ppStats $uri -recipe PPSTATS " . RECIPE; # Command to run ppStats
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-        run(command => $command, verbose => 1);
-    die "Unable to perform ppStats on exposure id $exp_tag: $error_code\n" if not $success;
+        cache_run(command => $command, verbose => 1);
+    die "Unable to perform ppStats on exposure id $exp_tag: $error_code\n"
+        if not $success;
     
     # Parse the output
@@ -123,4 +133,18 @@
 }
 
+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;
+    }
+}
+
 # Pau.
 
