...
my $session = get_session_id();
my $cache = get_cache_handle();
$cache->set( $session, [ 0, "" ] ); # no data yet
my $background = go_background( $session );
...
if( not $background->alive ) {
if( my $data = $cache->get( $session ) ){
return show_results( $data );
}
}
...
sub get_cache_handle {
use Cache::FileCache;
return Cache::FileCache->new
...
}
## stuffintocache.pl
#!/usr/bin/perl --
use strict; use warnings;
use Getopt::Long();
use Capture::Tiny qw/ capture /;
Main( @ARGV );
exit( 0 );
sub Main {
my %opt;
Getopt::Long::GetOptionsFromArray(
\@_,
\%opt,
'session=s',
...
)
my($stdout, $stderr, $exit) = capture {
system( $cmd, @args );
};
my $session = get_session_id();
my $cache = get_cache_handle();
$cache->set( $session, [ 1, $stdout, $stderr, $exit ] );
return;
}
|