summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--lib/KiokuDB/Backend/Memcachedb.pm41
1 files changed, 25 insertions, 16 deletions
diff --git a/lib/KiokuDB/Backend/Memcachedb.pm b/lib/KiokuDB/Backend/Memcachedb.pm
index e352eac..889d799 100644
--- a/lib/KiokuDB/Backend/Memcachedb.pm
+++ b/lib/KiokuDB/Backend/Memcachedb.pm
@@ -13,13 +13,6 @@ our $VERSION = "0.01";
with qw(
KiokuDB::Backend
KiokuDB::Backend::Serialize::Delegate
- KiokuDB::Backend::Role::Concurrency::POSIX
-);
-
-has create => (
- isa => "Bool",
- is => "ro",
- default => 0,
);
sub BUILD {
@@ -41,21 +34,37 @@ sub new_from_dsn_params {
$self->new( %args, db => $db );
}
-sub insert {
- my ( $self, @entries ) = @_;
+sub get {
+ my ( $self, @ids ) = @_;
+
my $db = $self->db;
- foreach my $entry ( @entries ) {
- $db->set( $entry->id, $self->serialize( $entry ) );
- }
+
+ my $entries = $self->db->get_multi( @ids );
+
+ my @objs;
+
+ foreach my $id ( @ids ) {
+ return unless exists $entries->{$id};
+ }
+
+ return map { $self->deserialize($_) } @{ $entries }{@ids};
}
-sub get {
- my ( $self, @ids ) = @_;
+sub insert {
+ my ( $self, @entries ) = @_;
my $db = $self->db;
- my @objs = map { $self->deserialize( $db->get( $_ ) ) } @ids;
- @objs;
+ foreach my $entry ( @entries ) {
+ my $id = $entry->id;
+
+ if ( $entry->deleted ) {
+ $db->delete( $id );
+ } else {
+ my $method = $entry->has_prev ? "replace" : "add";
+ die "error in $method $id" unless $db->$method( $id => $self->serialize($entry) );
+ }
+ }
}
sub exists {