Debian Codegraph @

lemonldap-ng-common/lib/Lemonldap/NG/Common/Apache/Session/Lock.pm

raw
1
2 package Lemonldap::NG::Common::Apache::Session::Lock;
3
4 use strict;
5
6 our $VERSION = '2.0.0';
7
8 sub new {
9 my $class = shift;
10 my $session = shift;
11
12 my $self = {};
13 $self->{args} = $session->{args};
14 bless $self, $class;
15 return $self;
16 }
17
18 sub module {
19 my $self = shift;
20 return $self->{args}->{lock_manager};
21 }
22
23 sub cache {
24 my $self = shift;
25
26 return $self->{cache} if $self->{cache};
27
28 my $module = $self->{args}->{localStorage};
29 eval "use $module;";
30 $self->{cache} = $module->new( $self->{args}->{localStorageOptions} );
31
32 return $self->{cache};
33 }
34
35 sub acquire_read_lock {
36 my $self = shift;
37 my $session = shift;
38
39 # Get session from cache
40 my $id = $session->{data}->{_session_id};
41 if ( $self->cache->get($id) ) {
42
43 # got session from cache, no need to ask for locks
44 }
45 else {
46 $self->module->acquire_read_lock($session);
47 }
48 }
49
50 sub acquire_write_lock {
51 my $self = shift;
52 my $session = shift;
53
54 $self->module->acquire_write_lock($session);
55 }
56
57 sub release_write_lock {
58 my $self = shift;
59 my $session = shift;
60
61 $self->module->release_write_lock($session);
62 }
63
64 sub release_all_locks {
65 my $self = shift;
66 my $session = shift;
67
68 $self->module->release_all_locks($session);
69 }
70
71 1;
72