lemonldap-ng/modules/lemonldap-ng-portal/example/scripts/purgeCentralCache

45 lines
925 B
Perl
Executable File

#!/usr/bin/perl
# Cleaner for Lemonldap::NG : removes old sessions from Apache::Session
#
# This module is written to be used by cron to clean old sessions from
# Apache::Session.
use Lemonldap::NG::Common::Conf;
use Lemonldap::NG::Common::Conf::Constants;
use Lemonldap::NG::Common::Apache::Session;
use strict;
my $lmconf = Lemonldap::NG::Common::Conf->new();
my $conf = $lmconf->getConf or die "Unable to get configuration ($!)";
my $tmp = $conf->{globalStorage};
eval "use $tmp";
die $@ if ($@);
$conf->{timeout} ||= 7200;
my @t;
$tmp->get_key_from_all_sessions(
$conf->{globalStorageOptions},
sub {
my $entry = shift;
my $id = shift;
push @t, $id if ( time - $entry->{_utime} > $conf->{timeout} );
undef;
}
);
for my $id (@t) {
my %h;
eval { tie %h, $tmp, $id, $conf->{globalStorageOptions} };
if ($@) {
next;
}
tied(%h)->delete;
}
1;