CHI::Driver::CacheCache - CHI wrapper for Cache::Cache


CHI documentation Contained in the CHI distribution.

Index


Code Index:

NAME

Top

CHI::Driver::CacheCache - CHI wrapper for Cache::Cache

VERSION

Top

version 0.49

SYNOPSIS

Top

    use CHI;

    my $cache = CHI->new(
        driver     => 'CacheCache',
        cc_class   => 'Cache::FileCache',
        cc_options => { cache_root => '/path/to/cache/root' },
    );

DESCRIPTION

Top

This driver wraps any Cache::Cache cache.

CONSTRUCTOR OPTIONS

Top

When using this driver, the following options can be passed to CHI->new() in addition to the CHI|general constructor options/constructor.

cc_class

Name of Cache::Cache class to create, e.g. Cache::FileCache. Required.

cc_options

Hashref of options to pass to Cache::Cache constructor. Required.

SEE ALSO

Top

CHI

AUTHOR

Top

Jonathan Swartz <swartz@pobox.com>

COPYRIGHT AND LICENSE

Top


CHI documentation Contained in the CHI distribution.

package CHI::Driver::CacheCache;
BEGIN {
  $CHI::Driver::CacheCache::VERSION = '0.49';
}
use Cache::Cache;
use Carp;
use Moose;
use strict;
use warnings;

extends 'CHI::Driver::Base::CacheContainer';

has 'cc_class'   => ( is => 'ro', isa => 'Str', required => 1 );
has 'cc_options' => ( is => 'ro', isa => 'HashRef', required => 1 );

__PACKAGE__->meta->make_immutable();

sub BUILD {
    my ( $self, $params ) = @_;

    $self->{_contained_cache} = $self->_build_contained_cache;
}

sub _build_contained_cache {
    my ($self) = @_;

    my $cc_class   = $self->{cc_class};
    my $cc_options = $self->{cc_options};
    my %subparams  = ( namespace => $self->namespace );

    Class::MOP::load_class($cc_class);

    my %final_cc_params = ( %subparams, %{$cc_options} );

    return $cc_class->new( \%final_cc_params );
}

1;




__END__