Permalink
Browse files

Caching results of AnyEvent::DNS::a

  • Loading branch information...
1 parent f95af15 commit 10833010505a12272fc703030e24ec03a14950d0 @despairr despairr committed Jun 12, 2010
Showing with 22 additions and 0 deletions.
  1. +22 −0 benchmark.pl
View
@@ -27,6 +27,28 @@
$AnyEvent::HTTP::set_proxy = $proxy;
$AnyEvent::HTTP::USERAGENT = $useragent;
+# Caching results of AnyEvent::DNS::a
+my $orig_anyeventdnsa = \&AnyEvent::DNS::a;
+my %cache;
+*AnyEvent::DNS::a = sub($$) {
+ my ($domain, $cb) = @_;
+
+ if ($cache{$domain}) {
+ $cb->( @{ $cache{$domain} } );
+ return;
+ }
+
+ $orig_anyeventdnsa->( $domain,
+ sub {
+ $cache{$domain} = [ @_ ];
+ $cb->( @_ );
+ }
+ );
+
+ return;
+};
+# End of caching
+
#on ctrl-c break run the end_bench sub.
$SIG{'INT'} = 'end_bench';

0 comments on commit 1083301

Please sign in to comment.