File: purgeCentralCache

package info (click to toggle)
lemonldap-ng 0.9.4.1-3
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 3,840 kB
  • ctags: 1,187
  • sloc: perl: 10,032; makefile: 478; xml: 93; sh: 73; sql: 69
file content (44 lines) | stat: -rwxr-xr-x 925 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/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;