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

File::Store - a file content caching system

SYNOPSIS

        use File::Store;

        my $contents1 = File::Store::get('/etc/passwd');
        my $contents2 = File::Store::get('/etc/passwd');

or

        use File::Store;
        my $store = new File::Store;

        my $contents1 = $store->get('/etc/passwd');
        my $contents2 = $store->get('/etc/passwd');
        $store->clear();

DESCRIPTION

This modules acts as an in-memory cache for files. Each file is read once unless the modification date changes; in which case the file is reread. Files can be automatically flushed based on time, size or number of files.

Files are read from the file system via the function get and cached in memory. Subsequent calls for the same file returns the cached file contents. If the file has been updated on disc, the file is re-read.

If no File::Store object is specified then a global store is used.

DEFAULT OPTIONS

The default options are

expire

How long, in seconds, to keep files in the cache. The default is always (0).

size

The maximum size, in bytes, of files kept in the cache. The default is 0 (infinite).

max

The maximum number of files kept in the cache. The default is 0 (infinite).

These defaults can be changed globally via the packages variables $File::Store::EXPIRE, $File::Store::SIZE and $File::Store::MAX respectively.

FUNCTIONS

new
        my $store = new File::Store (<options>);

Create a new File::Store object with options.

configure
        $store->configure(<options>);

Configure a File::Store.

get
        $store->get($file);

Return the contents of the specified file from the cache, reading the file from disc if necessary.

clear
        $store->clear();
        $store->clear($file1, $file2, ...);

Clear the caches inside a File::Store. If files are specified, information about those files are clear. Otherwise the whole cache is cleared.

purge
        $store->purge();

Remove any items in the cache according to the options expire, size and max. If the cache is too large, then the oldest items (according to their last use) are removed.

count
        $store->count();

Return the number of files in the File::Store.

size
        $store->size();

Return the size, in bytes, of the File::Store.

cached
        $store->cached($file);

Return the last modification time of a file contained in the cache. Return 0 if the file isn't cached.

fresh
        $store->fresh($file1, $file2, ...);

Return whether the list of files are up to date or not. Returns 1 if all files are fresh and undef otherwise.

SEE ALSO

Perl, Cache::Cache

VERSION

This is version 1.0 released 2008.

AUTHOR

        Anthony Fletcher arif+perl@cpan.org

COPYRIGHT

Copyright (c) 1998-2008 Anthony Fletcher. All rights reserved. This module is free software; you can redistribute them and/or modify them under the same terms as Perl itself.

This code is supplied as-is - use at your own risk.

2 POD Errors

The following errors were encountered while parsing the POD:

Around line 77:

=back doesn't take any parameters, but you said =back 4

Around line 431:

You forgot a '=back' before '=head1'