diff options
author | Daniel Friesel <derf@finalrewind.org> | 2015-11-29 17:35:54 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2015-11-29 17:35:54 +0100 |
commit | aa1ff3da725ff69336cb243fa316a800c75aa0f3 (patch) | |
tree | 8e39509958e38c4f99acf28b6e9d0acd60accf2e /lib/Travel | |
parent | c90be68e41b7f93172cd4fea40988eefda8bf455 (diff) |
actually use cache
Diffstat (limited to 'lib/Travel')
-rw-r--r-- | lib/Travel/Status/DE/IRIS.pm | 17 |
1 files changed, 16 insertions, 1 deletions
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 { |