- NAME
- SYNOPSIS
- DESCRIPTION
- EXAMPLE
- NOTES
- COPYRIGHT
- VERSION

# NAME

GT::Cache - Tied hash which caches output of functions.

# SYNOPSIS

        use GT::Cache;
        my %cache;
        tie %cache, 'GT::Cache', $size, \&function;

# DESCRIPTION

GT::Cache implements a simple but quick caching scheme for remembering the results of functions. It also implements a max size to prevent the cache from growing and drops least frequently requested entries first, making it very useful under mod_perl.

# EXAMPLE

        use GT::Cache;
        my %cache;
        tie %cache, 'GT::Cache', 100, \&complex_func;

        while (<>) {
            print "RESULT: ", $cache{$_}, "\n";
        }

        sub complex_func {
            my $input = shift;
            # .. do complex work.
            return $output;
        }

This will cache the results of complex_func, and only run it when the input is different. It stores a max of 100 entries at a time, with the least frequently requested getting dropped first.

# NOTES

Currently, you can only pass as input to the function a single scalar, and the output must be a single scalar. See the Memoize module in CPAN for a much more robust implementation.

# COPYRIGHT

Copyright (c) 2004 Gossamer Threads Inc. All Rights Reserved. http://www.gossamer-threads.com/

# VERSION

Revision: $Id: Cache.pm,v 1.13 2004/01/13 01:35:15 jagerman Exp $