# HG changeset patch # User Dominic Cleal # Date 1232905136 0 # Node ID 420807d41e047da1c7c73e7c34af8c8a2874b476 # Parent 61fb1a6de2c5522c165d949535472ce974b1102a Updating comments diff -r 61fb1a6de2c5 -r 420807d41e04 reproctool.cgi --- a/reproctool.cgi Sun Jan 25 17:36:03 2009 +0000 +++ b/reproctool.cgi Sun Jan 25 17:38:56 2009 +0000 @@ -41,10 +41,9 @@ my $str_items = $cgi->param('items'); # Generate the first page, where eve-central mineral prices are prefilled. -# TODO: depending on the traffic, cache these eve-central prices. - unless ($str_items) { + # Try and pull the marks out of a stored cache my $marks; if (-e $marks_cache) { @@ -52,6 +51,7 @@ $marks = fd_retrieve(*CACHE) || die("Can't read marks from cache: $!"); close CACHE; + # Check expiry time if (time > ($marks->{timestamp} + $marks_cache_expiry)) { $marks = undef; @@ -60,12 +60,14 @@ unless ($marks) { + # If cache was unavailable or had expired, pull again from eve-central my $ua = LWP::UserAgent->new; $ua->agent('reproctool'); my $resp = $ua->request(HTTP::Request->new(GET => $eve_central_url)); if ($resp->is_success) { + # Store as Mineral => 1234 $marks = { timestamp => time }; foreach (split(/[\n\r]/, $resp->content)) { @@ -79,6 +81,7 @@ || die("Unable to unlink cache $marks_cache: $!"); } + # Store into the cache open CACHE, "> $marks_cache" || die("Can't open cache $marks_cache to write: $!"); store_fd($marks, *CACHE) || die("Can't write to cache: $!"); @@ -86,6 +89,7 @@ } else { + # User can enter their own numbers if eve-central was down $marks->{$_} = 1 foreach ('Tritanium', 'Pyerite', 'Mexallon', 'Isogen', 'Nocxium', 'Zydrine', 'Megacyte', 'Morphite');