27 February 2007
This post may be outdated due to it was written on 2007. The links may be broken. The code may be not working anymore. Leave comments if needed.
Catalyst::Plugin::Session::Store::Memcached is much faster than DBIC. but that's not so fit our demand.
we have one function called "Ban a user", we remove the session of that user when he is banned. but Memcached Store don't have user_id field as key.

Cache::Memcached::Managed has one function named "group". so I hack that pm to support delete_session_data_by_user_id.

first when new Cache::Memcached::Managed we add:
        my $storage = $cfg->{memcached_obj} || Cache::Memcached::Managed->new(
data => "localhost:11211",
namespace => "catalyst_session",
group_names => [qw(user_id)],
%{ $cfg->{memcached_new_args} || {} },
),
so that we can set user_id when set a memcache key.
    $c->_session_memcached_storage->set(
@{ $c->_session_memcached_arg_fudge },
(
$key =~ /^(?:expires|session|flash)/
? ( expiration => $c->session_expires )
: ()
),
id => $key,
value => $data,
user_id => $user_id,
)
at end, delete_session_data_by_user_id is pretty simple.
sub delete_session_data_by_user_id {
my ( $c, $user_id ) = @_;

return unless ($user_id > 0);
$c->_session_memcached_storage->delete_group( user_id => $user_id );
}

have fun!


blog comments powered by Disqus