The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Cache::CacheFactory::Expiry::LastModified - File last-modified date dependencies expiry policy for Cache::CacheFactory.

DESCRIPTION

Cache::CacheFactory::Expiry::LastModified is an expiry (pruning and validity) policy for Cache::CacheFactory.

It provides the ability to prune or invalidate cache entries by comparing the create time of the entry to the last-modified time of a list of files (AKA dependencies).

STARTUP OPTIONS

There are no startup options for Cache::CacheFactory::Expiry::LastModified.

STORE OPTIONS

The following options may be set when storing a key, see the Cache::CacheFactory documentation for details on how to do this.

dependencies => $filename
dependencies => [ $filename1, $filename2, ... ]

This marks the cache entry as depending on the provided filenames, if any of these files are modified after the cache entry is created the entry is considered invalid or is eligible for pruning.

This is done by comparing the last-modified time (as read via stat()) to the created_at value for the cache entry, this will normally be reliable but be aware that some programs (tar for example) will falsify last-modified times, and it's also possible to manipulate the created_at time of a cache entry when first storing it.

Also if the process you are using to generate the content from source is lengthy it is probably best to take a timestamp from before you read the source files and supply this as created_at value when doing $cache->set() - this will ensure that any modifications to the source files between the time you read their content and you stored the generated content will be correctly detected.

For example:

  $time = time();
  $data = expensive_read_and_build_data_from_file( $file );
  $cache->set(
      key          => 'mykey',
      data         => $data,
      created_at   => $time,
      dependencies => $file,
      );

KNOWN ISSUES AND BUGS

stat() is expensive

Calling stat() on a lot of files is quite expensive, especially if you're doing it repeatedly. There really ought to be a mechanism to say that you want to cache the results for a period. Ah, if only someone had written a handy caching module...

This will probably make it into a future release.

SEE ALSO

Cache::CacheFactory, Cache::Cache, Cache::CacheFactory::Object, Cache::CacheFactory::Expiry::Base

AUTHORS

Original author: Sam Graham <libcache-cachefactory-perl BLAHBLAH illusori.co.uk>

Last author: $Author: illusori $

COPYRIGHT

Copyright 2008-2010 Sam Graham.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.