@@ -431,21 +431,32 @@ sub update_match_counter($cache) { # dead
431
431
}
432
432
433
433
sub current_version ($self ) {
434
+ my $now = time ();
435
+ my $cache_ttl = 600; # 10 minutes in seconds
434
436
435
- # cache the current grep metacpan version
436
- $self -> {__version__ } //= join (
437
- ' -' ,
438
- $grepcpan::VERSION ,
439
- ' cache' => $self -> config()-> {' cache' }-> {' version' },
440
- ' grep' => eval {
441
- scalar Git::Repository-> new(
442
- work_tree => $self -> root,
443
- { git => $self -> git_binary }
444
- )-> run(qw{ rev-parse --short HEAD} );
445
- } // ' ' ,
446
- ' cpan' => eval { scalar $self -> git-> run(qw{ rev-parse --short HEAD} ) }
447
- // ' ' ,
448
- );
437
+ # Check if we need to refresh the cache
438
+ if ( !exists $self -> {__version__ }
439
+ || !exists $self -> {__version_timestamp__ }
440
+ || ( $now - $self -> {__version_timestamp__ } ) > $cache_ttl )
441
+ {
442
+
443
+ $self -> {__version__ } = join (
444
+ ' -' ,
445
+ $grepcpan::VERSION ,
446
+ ' cache' => $self -> config()-> {' cache' }-> {' version' },
447
+ ' grep' => eval {
448
+ scalar Git::Repository-> new(
449
+ work_tree => $self -> root,
450
+ { git => $self -> git_binary }
451
+ )-> run(qw{ rev-parse --short HEAD} );
452
+ } // ' ' ,
453
+ ' cpan' =>
454
+ eval { scalar $self -> git-> run(qw{ rev-parse --short HEAD} ) }
455
+ // ' ' ,
456
+ );
457
+
458
+ $self -> {__version_timestamp__ } = $now ;
459
+ }
449
460
450
461
return $self -> {__version__ };
451
462
}
0 commit comments