Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Caching results of AnyEvent::DNS::a

  • Loading branch information...
commit 10833010505a12272fc703030e24ec03a14950d0 1 parent f95af15
despairr authored

Showing 1 changed file with 22 additions and 0 deletions. Show diff stats Hide diff stats

  1. 22  benchmark.pl
22  benchmark.pl
@@ -27,6 +27,28 @@
27 27
 $AnyEvent::HTTP::set_proxy    = $proxy;
28 28
 $AnyEvent::HTTP::USERAGENT    = $useragent;
29 29
 
  30
+# Caching results of AnyEvent::DNS::a
  31
+my $orig_anyeventdnsa = \&AnyEvent::DNS::a;
  32
+my %cache;
  33
+*AnyEvent::DNS::a = sub($$) {
  34
+    my ($domain, $cb) = @_;
  35
+
  36
+    if ($cache{$domain}) {
  37
+	$cb->( @{ $cache{$domain} } );
  38
+	return;
  39
+    }
  40
+
  41
+    $orig_anyeventdnsa->( $domain,
  42
+	sub {
  43
+	    $cache{$domain} = [ @_ ];
  44
+	    $cb->( @_ );
  45
+	}
  46
+    );
  47
+
  48
+    return;
  49
+};
  50
+# End of caching
  51
+
30 52
 #on ctrl-c break run the end_bench sub.
31 53
 $SIG{'INT'} = 'end_bench';
32 54
 

0 notes on commit 1083301

Please sign in to comment.
Something went wrong with that request. Please try again.