Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

cache retrieval has to happen after the params for the request have b…

…een sorted out, so iterated requests can work properly
  • Loading branch information...
commit 4f1c9e72a78429e03d3f4d07f5f359eb61521c32 1 parent 549d938
@wchristian wchristian authored
Showing with 17 additions and 16 deletions.
  1. +17 −16 lib/Net/LastFMAPI.pm
View
33 lib/Net/LastFMAPI.pm
@@ -202,22 +202,6 @@ sub lastfm {
my ($method, @params) = @_;
$method = lc($method);
- my $cache = $cache;
- if ($cache) {
- unless (-d $cache) {
- $cache = $cache_dir;
- make_path($cache);
- }
- my $file = "$cache/".md5_hex(encode_json(\@_));
- if (-f $file) {
- my $data = loadfile($file);
- return _rowify_content( $data->{content} );
- }
- else {
- $cache = $file
- }
- }
-
my %params;
my $i = 0;
while (my $p = shift @params) {
@@ -249,6 +233,23 @@ sub lastfm {
sign(\%params);
%last_params = %params;
+
+ my $cache = $cache;
+ if ( $cache ) {
+ unless ( -d $cache ) {
+ $cache = $cache_dir;
+ make_path( $cache );
+ }
+ my $cache_key_json = encode_json( [ map { $_, $params{$_} } sort keys %params ] );
+ my $file = "$cache/" . md5_hex( $cache_key_json );
+ if ( -f $file ) {
+ my $data = loadfile( $file );
+ return _rowify_content( $data->{content} );
+ }
+
+ $cache = $file;
+ }
+
my $res;
if ($methods->{$method}->{post}) {
$res = $ua->post($url, Content => \%params);
Please sign in to comment.
Something went wrong with that request. Please try again.