| 1 | |||
| 2 | package Apache::Session::Store::NoSQL::Cassandra; | ||
| 3 | |||
| 4 | use strict; | ||
| 5 | use Net::Cassandra; | ||
| 6 | |||
| 7 | use vars qw($VERSION); | ||
| 8 | $VERSION = '0.1'; | ||
| 9 | |||
| 10 | sub new { | ||
| 11 | my ( $class, $session ) = @_; | ||
| 12 | my $self; | ||
| 13 | |||
| 14 | $self->{cache} = Net::Cassandra->new( %{$session} )->client; | ||
| 15 | |||
| 16 | bless $self, $class; | ||
| 17 | } | ||
| 18 | |||
| 19 | sub insert { | ||
| 20 | my ( $self, $session ) = @_; | ||
| 21 | $self->{cache}->insert( | ||
| 22 | 'Keyspace1', | ||
| 23 | $session->{data}->{_session_id}, | ||
| 24 | Net::Cassandra::Backend::ColumnPath->new( | ||
| 25 | { column_family => 'Standard1', column => 'name' } | ||
| 26 | ), | ||
| 27 | $session->{serialized}, | ||
| 28 | time, | ||
| 29 | Net::Cassandra::Backend::ConsistencyLevel::QUORUM | ||
| 30 | ); | ||
| 31 | } | ||
| 32 | |||
| 33 | *update = *insert; | ||
| 34 | |||
| 35 | sub materialize { | ||
| 36 | my ( $self, $session ) = @_; | ||
| 37 | $self->{cache}->get( | ||
| 38 | 'Keyspace1', | ||
| 39 | $session->{data}->{_session_id}, | ||
| 40 | Net::Cassandra::Backend::ColumnPath->new( | ||
| 41 | { column_family => 'Standard1', column => 'name' } | ||
| 42 | ), | ||
| 43 | Net::Cassandra::Backend::ConsistencyLevel::QUORUM | ||
| 44 | ) or die 'Object does not exist in data store.'; | ||
| 45 | } | ||
| 46 | |||
| 47 | sub remove { | ||
| 48 | my ( $self, $session ) = @_; | ||
| 49 | $self->{cache}->remove( | ||
| 50 | 'Keyspace1', | ||
| 51 | $session->{data}->{_session_id}, | ||
| 52 | Net::Cassandra::Backend::ColumnPath->new( | ||
| 53 | { column_family => 'Standard1', column => 'name' } | ||
| 54 | ), | ||
| 55 | time, | ||
| 56 | Net::Cassandra::Backend::ConsistencyLevel::QUORUM | ||
| 57 | ); | ||
| 58 | } | ||
| 59 | |||
| 60 | 1; | ||
| 61 | |||
| 62 | __END__ |