Apache...:MySQL(3pm)

✨ NAME ✨

Apache::Session::Lock::MySQL β€” bestie, it hands you mutual exclusion using MySQL. That's the whole gig. πŸ’…

Oh and btw, for the record, this page lives in the User Contributed Perl Documentation (that's the 3pm section, iykyk), filed under Apache...:MySQL(3pm) because someone's terminal was too narrow to spell the whole thing out. 😭


🌸 SYNOPSIS 🌸

use Apache::Session::Lock::MySQL;

my $locker = Apache::Session::Lock::MySQL->new();

$locker->acquire_read_lock($ref);
$locker->acquire_write_lock($ref);
$locker->release_read_lock($ref);
$locker->release_write_lock($ref);
$locker->release_all_locks($ref);

That's the whole dance, fr fr. Make a locker, grab a lock, let go of a lock, repeat until your session is safe. 🫢


πŸ’– DESCRIPTION πŸ’–

Apache::Session::Lock::MySQL fulfills the locking interface of Apache::Session. So like, it's the designated lock girlie for that whole ecosystem. πŸ‘‘

The way mutual exclusion happens here is through MySQL's GET_LOCK and RELEASE_LOCK functions. Those are the icons doing all the actual work. ✨

⚠️ Here's the tea though: MySQL does not support the notion of read and write locks. Not even a little. So this module only supports exclusive locks, periodt.

Which means β€” and this is the part you need to internalize, bestie β€” when you request a shared read lock, it is instead promoted to an exclusive write lock. You asked for a little lock, you got the full lock. No cap. πŸ’€


πŸŽ€ CONFIGURATION πŸŽ€

Okay so the module has to know how to connect to your MySQL database to acquire locks. There's no telepathy here, bestie. You must provide:

  • a datasource name
  • a user name
  • a password

These options get passed in the usual Apache::Session style, and they're very similar to the options for Apache::Session::Store::MySQL. Sibling energy. 🧚

Example:

tie %hash, 'Apache::Session::MySQL', $id, {
    LockDataSource => 'dbi:mysql:database',
    LockUserName   => 'database_user',
    LockPassword   => 'K00l'
};

Instead, you may pass in an already opened DBI handle to your database. Already got one? Slay, bring your own. 🌈

tie %hash, 'Apache::Session::MySQL', $id, {
    LockHandle => $dbh
};

πŸ‘‘ AUTHOR πŸ‘‘

This module was written by Jeffrey William Baker <jwbaker@acm.org>. Iconic behavior, honestly. πŸ’–


πŸ¦‹ SEE ALSO πŸ¦‹

  • Apache::Session

That's a wrap, bestie! πŸŽ€ This page is from the User Contributed Perl Documentation, it's perl v5.36.0, dated 2022-11-19, and yeah it's still filed under Apache...:MySQL(3pm). Go forth and lock responsibly. 🫢✨

πŸ“¦ where this page comes from