From aa1ff3da725ff69336cb243fa316a800c75aa0f3 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sun, 29 Nov 2015 17:35:54 +0100 Subject: actually use cache --- lib/Travel/Status/DE/IRIS.pm | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'lib/Travel/Status/DE') diff --git a/lib/Travel/Status/DE/IRIS.pm b/lib/Travel/Status/DE/IRIS.pm index d178c7e..e76e1f9 100644 --- a/lib/Travel/Status/DE/IRIS.pm +++ b/lib/Travel/Status/DE/IRIS.pm @@ -125,6 +125,16 @@ sub get_with_cache { say "GET $url"; } + if ($cache) { + my $content = $cache->thaw($url); + if ($content) { + if ( $self->{developer_mode} ) { + say ' cache hit'; + } + return ( ${$content}, undef ); + } + } + say ' cache miss'; my $ua = $self->{user_agent}; my $res = $ua->get($url); @@ -132,8 +142,13 @@ sub get_with_cache { if ( $res->is_error ) { return ( undef, $res->status_line ); } + my $content = $res->decoded_content; + + if ($cache) { + $cache->freeze( $url, \$content ); + } - return ( $res->decoded_content, undef ); + return ( $content, undef ); } sub get_station { -- cgit v1.2.3