Cache-CacheFactory
view release on metacpan or search on metacpan
t/40-expiry-lastmodified.t view on Meta::CPAN
if( time() == $time )
{
sleep( 1 ); # So that the last modified time is definitely in the past.
}
if( time() == $time )
{
sleep( 1 ); # So that the last modified time is definitely in the past.
}
skip "Unable to sleep until dependency file mtime is in the past." => 5
if time() == $time;
ok( $cache = Cache::CacheFactory->new(
storage => 'memory',
validity => 'lastmodified',
), "construct cache" );
$key = 'valid';
$cache->set(
key => $key,
data => $vals{ $key },
dependencies => $file,
);
$key = 'valid';
is( $cache->get( $key ), $vals{ $key }, "immediate $key fetch" );
$cache->purge();
$key = 'valid';
is( $cache->get( $key ), $vals{ $key }, "post-purge immediate $key fetch" );
$time = touch( $file );
skip "Unable to touch dependency file." => 2 unless $time;
$key = 'valid';
is( $cache->get( $key ), undef, "post-touch $key fetch" );
$cache->purge();
$key = 'valid';
is( $cache->get( $key ), undef, "post-purge post-touch $key fetch" );
}
unlink( $file ) if $file and -e $file;
sub touch
{
my ( $filename ) = @_;
my ( $fh, $time, $mtime );
$time = time();
$fh = IO::File->new( "> $filename" );
unless( $fh )
{
diag( "Couldn't open $filename for write." );
return( 0 );
}
$fh->print( "touched at $time\n" );
$fh->close();
$mtime = (stat( $filename ))[ 9 ];
return( $mtime ) if $mtime >= $time;
diag( "$filename mtime is in the past - last-mod-time: " .
localtime( $mtime ) . " vs file-open-time: " .
localtime( $time ) . "." );
return( 0 );
}
( run in 0.589 second using v1.01-cache-2.11-cpan-140bd7fdf52 )