NetSDS::Session(3pm)

πŸ“¦
version 1.301 Β· 2 versions
, in debian bookworm, debian trixie, ubuntu jammy, ubuntu noble, ubuntu resolute

πŸ‘‘ NetSDS::Session πŸ‘‘

okay bestie, welcome to NetSDS::Session(3pm) β€” part of the User Contributed Perl Documentation. and it is genuinely one of the most useful little modules you'll ever meet. it's giving "I store your sessions in memcached and I do it flawlessly." no cap. πŸ¦‹


✨ NAME ✨

NetSDS::Session β€” memcached based session storage API πŸ’–

like. that's it. that's the whole name. and honestly? iconic.


🌸 SYNOPSIS 🌸

here's how you actually use it, babes:

use NetSDS::Session;

# Connecting to Memcached server
my $sess = NetSDS::Session->new(
        host => '12.34.56.78',
        port => '12345',
);

...

# Retrieve session key somehow
$session_key = $cgi->param('sess_key');

$sess->open($session_key);

my $filter = $sess->get('filter');
...
$sess->set('filter', $new_filter);
...
$sess->close();

1;

the little dot-dot-dot bits are literally just "you do stuff here" β€” it's a vibe, not a real method. πŸ’…


πŸ’œ DESCRIPTION πŸ’œ

so NetSDS::Session gives you an API for session data storage, and the whole thing runs on top of a Memcached server. ✨

every session is a hash reference structure, and it's identified by a UUID string. like a little name tag for your data. πŸŽ€

the most reasonable usage of this module is temporary data storing for a web based GUI between HTTP requests β€” that's the main character use case. but ngl, it's possible to find some other tasks too. it's flexible like that. πŸ’

lowkey important detail: internally, the session structure is transformed to/from a JSON string whenever it interacts with Memcached. that's just how it rolls. 🌈


🧚 CLASS API 🧚

okay this is the part where we meet the methods one by one. they're all so good. let's go. πŸ‘‘

⭐ new(%params) β€” class constructor

this is the constructor, and it does two things: it establishes a connection to the memcached server, and it sets the default session parameters. like a little welcome committee. 🫢

Parameters:

  • host β€” the memcached server hostname or IP address (default: 127.0.0.1)
  • port β€” the memcached server TCP port (default: 11211)

Example:

my $sess_hdl = NetSDS::Session->new(
        host => '12.34.56.78',
        port => '99999',
);

see how easy that was? obsessed. πŸ’–

πŸ¦‹ open($sess_id) β€” open session

this one retrieves session data from the server by session key (that's a UUID string, remember? πŸŽ€).

and if no session exists? don't stress β€” you just get an empty hashref back. no drama. ✨

πŸ’… id() β€” get session id

returns the current session id. that's it. that's the whole thing. short and sweet. πŸ’œ

Example:

my $sess_id = $sess->id();

🌸 set($key, $value) β€” set session parameter

sets a new session parameter value, identified by its key. super straightforward, we love to see it. πŸ“

Example:

$sess->set('order', 'id desc');

🌈 get($key) β€” get session parameter

returns a session parameter value by its key. the reading counterpart to set. balance. harmony. πŸ’«

Example:

my $order = $sess->get('order');

πŸŽ€ delete($key) β€” delete session parameter by key

deletes a session parameter by its key. bye bestie! πŸ‘‹

and it returns the updated session data as a hash reference β€” so you're not left hanging. 🫢

Example:

$sess->delete('order');

πŸ”₯ clear() β€” clear session data

this method clears all session data. everything. gone. clean slate energy. ✨

Example:

$sess->clear();

⭐ sync() β€” save session

synchronizes the session data on the Memcached server. like hitting save but for your whole session. πŸ’Ύβœ¨

Example:

$sess->sync();

πŸ‘‘ close() β€” save and close session

this method saves all data to the server AND clears the current session id and data from the object. two-for-one. main character behaviour fr fr. πŸ’…

Example:

$session->close();

(note: that example uses a slightly different variable name β€” cute little quirk, and we keep the code exactly as written 😌)


🫢 SEE ALSO 🫢

  • Cache::Memcached::Fast β€” XS implementation of Memcached API
  • JSON β€” JSON encoding/decoding API

both absolute icons, go check them out. πŸ’–


πŸ’œ AUTHORS πŸ’œ

  • Michael Bochkaryov <misha@rattler.kiev.ua>

🌸 THANKS 🌸

  • Yana Kornienko β€” for initial module implementation

we love a shoutout to the originator. 🫢


πŸ“œ LICENSE πŸ“œ

Copyright (C) 2008-2009 Net Style Ltd.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

no warranty bestie β€” it's giving "use at your own risk" but make it legal. πŸ’€

and that's the whole page!! this was NetSDS::Session(3pm) β€” rendered by perl v5.32.1 on 2021-12-26 πŸ’– thanks for reading, ily, go store some sessions responsibly. πŸŽ€βœ¨