Skip to content

Instantly share code, notes, and snippets.

@c9s
Created September 13, 2009 02:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save c9s/186056 to your computer and use it in GitHub Desktop.
Save c9s/186056 to your computer and use it in GitHub Desktop.
use warnings;
use strict;
use threads qw(yield);
# require Vimana::VimOnline::ScriptPage;
sub get_cache {
use Cache::Memory;
return Cache::Memory->new(
namespace => 'MyNamespace',
default_expires => '600 sec' );
}
my $f = async {
warn "f1 start";
my $cache = get_cache();
yield();
for ( 1 .. 10 ) {
warn $_;
sleep 1;
$cache->set( $_ , $_ );
}
};
my $f2 = async {
warn "f2 start";
my $cache = get_cache();
yield();
for ( 20 .. 30 ) {
warn $_;
sleep 1;
$cache->set( $_ , $_ );
}
};
$f->join();
$f2->join();
my $cache = get_cache();
warn $cache->count( );
warn 'END';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment