NAME

CHI::Stats - Record and report per-namespace cache statistics

SYNOPSIS

    # Turn on statistics collection
    CHI->stats->enable();

    # Perform cache operations

    # Flush statistics to logs
    CHI->stats->flush();

    ...

    # Parse logged statistics
    my $results = CHI->stats->parse_stats_logs($file1, ...);

DESCRIPTION

CHI can record statistics, such as number of hits, misses and sets, on a per-namespace basis and log the results to your Log::Any logger. You can then parse the logs to get a combined summary.

A single CHI::Stats object is maintained for each CHI root class, and tallies statistics over any number of CHI::Driver objects.

Statistics are reported when you call the "flush" method. You can choose to this once at process end, or on a periodic basis.

STATISTICS

The following statistics are tracked:

METHODS

enable =item disable =item enabled

Enable, disable, and query the current enabled status.

When stats are enabled, each new cache object will collect statistics. Enabling and disabling does not affect existing cache objects. e.g.

    my $cache1 = CHI->new(...);
    CHI->stats->enable();
    # $cache1 will not collect statistics
    my $cache2 = CHI->new(...);
    CHI->stats->disable();
    # $cache2 will continue to collect statistics
flush

Log all statistics to Log::Any (at Info level in the CHI::Stats category), then clear statistics from memory. There is one log message per cache label and namespace, looking like:

    CHI stats: namespace='Foo'; cache='File'; start=20090102:12:53:05; end=20090102:12:58:05; absent_misses=10; expired_misses=20; hits=50; set_key_size=6; set_value_size=20; sets=30
parse_stats_logs (log1, log2, ...)

Parses logs output by CHI::Stats and returns a listref of stats totals by root class, cache label, and namespace. e.g.

    [
     {root_class => 'CHI', cache =>'File', namespace => 'Foo', absent_misses => 100, expired_misses => 200, ... },
     {root_class => 'CHI', cache =>'File', namespace => 'Bar', ... },
    ]

Lines with the root class, cache label, and namespace are summed together. Non-stats lines are ignored.

Each parameter to this method may be a filename or a reference to an open filehandle.