The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Petal::Cache::Disk - Caches generated code on disk.

SYNOPSIS

  use Petal::Cache::Disk;
  my $data = Petal::Cache::Disk->get ('foo.html');
  unless (defined $data)
  {
    $data = complicated_long_compute_thing();
    Petal::Cache::Disk->set ($data);
  }

DESCRIPTION

  A simple cache module to avoid re-generating the Perl code from the
template file every time

GLOBALS

$TMP_DIR

Temp directory in which to store the cached file. If left to undef, File::Spec->tmpdir will be used instead.

$PREFIX

Name that should prefix the cached files. By default, set to 'petale_cache_', i.e. 'foo.html' might be stored as petale_cache_4e38e18f1c6bedaaf174f95310a938c2

METHODS

All the methods are static methods.

$class->get ($file);

Returns the cached data if its last modification time is more recent than the last modification time of the template Returns the code for template file $file, undef otherwise

$class->set ($file, $data);

Sets the cached data for $file.

$class->is_ok ($file);

Returns TRUE if the cache is still fresh, FALSE otherwise.

$class->compute_key ($file);

Computes a cache 'key' for $file, which should be unique. (Well, currently an MD5 checksum is used, which is not *exactly* unique but which should be good enough)

$class->cached_mtime ($file);

Returns the last modification date of the cached data for $file

$class->current_mtime ($file);

Returns the last modification date for $file

$class->cached ($key);

Returns the cached data for $key

$class->tmp;

Returns the temp directory in which the cached data is kept

AUTHOR

Jean-Michel Hiver <jhiver@mkdoc.com>

This module is redistributed under the same license as Perl itself.