Skip to content

Instantly share code, notes, and snippets.

@earino
Created July 26, 2012 19:26
Show Gist options
  • Save earino/3184000 to your computer and use it in GitHub Desktop.
Save earino/3184000 to your computer and use it in GitHub Desktop.
Using caching
my $pm = Parallel::ForkManager->new($PROCESSES);
my @list_of_work = qw/ BLAH BLAH BLAH /;
my @list_of_endpoints = qw/ YADDA YADDA YADDA /;
my $cache = CHI->new(
driver => 'FastMmap',
root_dir => $SOME_DIRECTORY,
cache_size => $SIZE,
);
for my $unit_of_work (@list_of_work) {
my $pid = $pm->start and next;
for my $endpoint (@list_of_endpoints) {
my $value_retrieved = $cache->compute($unit_of_work, $EXPIRATION, sub {
retrieve_value_from_stuff($unit_of_work);
});
do_stuff_to($value_retrieved);
push_value_retrieved_to($endpoint);
}
$pm->finish; # Terminates the child process
}
$pm->wait_all_children;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment