Subject: | Why doesn't this work? |
I'm sorry to bother you with what I am sure is a bug in my code or a failure in my understanding, rather than a problem with your code or documentation, but please would you tell me why this code fails?
#!/usr/bin/env perl
use strict;
use warnings;
use CHI;
my $config;
$config->{memory_cache}->{driver} = 'Memcached';
$config->{memory_cache}->{server} = '127.0.0.1';
my $cache = create_memory_cache({ config => $config, namespace => 'foo' });
$cache->set('xyzzy', 'plugh', '1 day');
die unless $cache->get('xyzzy');
sub create_memory_cache {
my %args = (ref($_[0]) eq 'HASH') ? %{$_[0]} : @_;
my $config = $args{'config'};
die 'config is not optional' unless($config);
my $driver = $config->{memory_cache}->{driver};
my %chi_args = (
driver => $driver,
namespace => $args{'namespace'}
);
my @server;
$server[0] = $config->{memory_cache}->{server};
if($config->{memory_cache}->{'port'}) {
$server[0] = ':' . $config->{memory_cache}->{port};
} else {
$server[0] .= ':11211';
}
$chi_args{'server'} = \@server;
return CHI->new(%chi_args);
}
TIA.