Cache::CacheFactory::Expiry::LastModified - File last-modified date dependencies expiry policy for Cache::CacheFactory.
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).
There are no startup options for Cache::CacheFactory::Expiry::LastModified.
The following options may be set when storing a key, see the Cache::CacheFactory documentation for details on how to do this.
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.
stat()
created_at
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.
$cache->set()
For example:
$time = time(); $data = expensive_read_and_build_data_from_file( $file ); $cache->set( key => 'mykey', data => $data, created_at => $time, dependencies => $file, );
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.
Cache::CacheFactory, Cache::Cache, Cache::CacheFactory::Object, Cache::CacheFactory::Expiry::Base
Original author: Sam Graham <libcache-cachefactory-perl BLAHBLAH illusori.co.uk>
Last author: $Author: illusori $
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.
To install Cache::CacheFactory, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Cache::CacheFactory
CPAN shell
perl -MCPAN -e shell install Cache::CacheFactory
For more information on module installation, please visit the detailed CPAN module installation guide.