| Line | |
|---|
| 1 |
package Resmon::ExtComm; |
|---|
| 2 |
|
|---|
| 3 |
use strict; |
|---|
| 4 |
require Exporter; |
|---|
| 5 |
use vars qw/@ISA @EXPORT/; |
|---|
| 6 |
|
|---|
| 7 |
@ISA = qw/Exporter/; |
|---|
| 8 |
@EXPORT = qw/cache_command/; |
|---|
| 9 |
|
|---|
| 10 |
my %commhist; |
|---|
| 11 |
my %commcache; |
|---|
| 12 |
|
|---|
| 13 |
sub cache_command($$;$) { |
|---|
| 14 |
my ($command, $expiry, $timeout) = @_; |
|---|
| 15 |
$timeout ||= $expiry; |
|---|
| 16 |
|
|---|
| 17 |
my $now = time; |
|---|
| 18 |
if($commhist{$command}>$now) { |
|---|
| 19 |
return $commcache{$command}; |
|---|
| 20 |
} |
|---|
| 21 |
# TODO: timeouts |
|---|
| 22 |
$commcache{$command} = `$command`; |
|---|
| 23 |
$commhist{$command} = $now + $expiry; |
|---|
| 24 |
return $commcache{$command}; |
|---|
| 25 |
} |
|---|
| 26 |
|
|---|
| 27 |
1; |
|---|