X-Git-Url: http://gb7djk.dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FRoute%2FNode.pm;h=4aa8be9ead142bdee079e45a11150d9f29a95d07;hb=b55a5be0062fb96613a2f42c25de550d69283b7a;hp=76d987572e3e789f6beee90ba9a0ed0bfcddbcf3;hpb=ef77e5488c4cc47afe272f6220cc3fa0cddc5829;p=spider.git diff --git a/perl/Route/Node.pm b/perl/Route/Node.pm index 76d98757..4aa8be9e 100644 --- a/perl/Route/Node.pm +++ b/perl/Route/Node.pm @@ -12,6 +12,8 @@ use DXDebug; use Route; use Route::User; use DXUtil; +use DXJSON; +use Time::HiRes qw(gettimeofday); use strict; @@ -38,6 +40,7 @@ $filterdef = $Route::filterdef; %list = (); $max = 0; $obscount = 3; +our $cachefn = localdata('route_node_cache'); sub count { @@ -392,6 +395,39 @@ sub PC92C_dxchan return (%{$parent->{PC92C_dxchan}}); } +sub TO_JSON { return { %{ shift() } }; } + +sub write_cache +{ + my $json = DXJSON->new; + $json->canonical(isdbg('routecache')); + + my $ta = [ gettimeofday ]; + my @s; + eval { + while (my ($k, $v) = each %list) { + push @s, "$k:" . $json->encode($v) . "\n"; + } + }; + if (!$@ && @s) { + my $fh = IO::File->new(">$cachefn") or confess("writing $cachefn $!"); + if (isdbg("routecache")) { + $fh->print(sort @s); + } + else { + $fh->print(@s); + } + $fh->close; + } else { + dbg("Route::Node:Write_cache error '$@'"); + return; + } + $json->indent(0)->canonical(0); + my $diff = _diffms($ta); + dbg("Route::Node:WRITE_CACHE time to write: $diff mS"); +} + + sub DESTROY { my $self = shift;