Cache-Memcached-XS

 view release on metacpan or  search on metacpan

lib/Cache/Memcached/XS.pm  view on Meta::CPAN

package Cache::Memcached::XS;

use 5.008006;
use strict;
use warnings;

our $VERSION = '0.01';

require XSLoader;
XSLoader::load('Cache::Memcached::XS', $VERSION);

use Storable;

# flag definitions
use constant F_STORABLE => 1;
use constant F_COMPRESS => 2;

# size savings required before saving compressed value
use constant COMPRESS_SAVINGS => 0.20; # percent

use vars qw($HAVE_ZLIB);

BEGIN {
    $HAVE_ZLIB = eval "use Compress::Zlib (); 1;";
}

sub new
{
	my $this	=	shift;
	my $class	=	ref($this) || $this;
	my $args	=	shift;
	my $self	=	{};

	bless $self,$class;

	$self->{mc}	=	mc_new();
	if (defined $args->{servers})
	{
		$self->set_servers($args->{servers});
	}
	$self->{$_} = $args->{$_} for (qw(readonly compress_threshold));

	return $self;
}

sub set_servers
{
	my $self	=	shift;
	my $servers	=	shift;

	return if !ref $servers || ref $servers ne "ARRAY";
	for my $server (@$servers)
	{
		if (ref $server)
		{
			mc_server_add4($self->{mc},$server->[0]) for ( 1 .. ($server->[1] || 1));
		}
		else
		{
			mc_server_add4($self->{mc},$server);
		}
	}
}

sub set_compress_threshold
{
	my $self	=	shift;
	my $threshold	=	shift;

	$self->{compress_threshold}	=	$threshold;
}

sub set_readonly
{
	my $self	=	shift;
	my $readonly	=	shift;

	$self->{readonly}	=	$readonly;
}



( run in 0.635 second using v1.01-cache-2.11-cpan-d8267643d1d )