package MooseX::Cache::Meta::Class;
use strict;
use Moose;
use Cache::MemoryCache;

extends qw(Moose::Meta::Class);

has Cache => (
    reader  => 'get_cache_handler',
    writer  => 'set_cache_handler',
    isa     => 'Cache::BaseCache',
    is      => 'rw',
    default => sub {
        return new Cache::MemoryCache( { 'namespace' => $_[0]->name, } );
    },
    handles => [qw(get_keys)]
);

use Moose;

extends 'Moose::Meta::Class';

override 'construct_instance' => sub {
    my ( $class, %params ) = @_;
    return $class->get_meta_instance->find_instance( $params{oid} )
      if $params{oid};
    super();
};

sub initialize {
    my $class = shift;
    my $pkg   = shift;
    $class->SUPER::initialize(
        $pkg,
        'instance_metaclass' => 'MooseX::Cache::Meta::Instance',
        @_
    );
}

no Moose;
1;
__END__
