---
name: "Data::Session::Driver::Memcached"
section: "3pm"
platform: "linux"
package: "libdata-session-perl"
version: "1.18-2"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/Data::Session::Driver::Memcached"
---

# Data::Session::Driver::Memcached(3pm)

A persistent session manager

## NAME

Data::Session::Driver::Memcached - A persistent session manager

## Synopsis

See Data::Session for details.

## Description

Data::Session::Driver::Memcached allows Data::Session to manipulate sessions Cache::Memcached.

To use this module do both of these:

- o Specify a driver of type Memcached, as Data::Session -\> new(type =\> 'driver:Memcached ...')

  - o Specify a cache object of type Cache::Memcached as Data::Session -\> new(cache =\> $object)

  See scripts/memcached.pl.

## Case-sensitive Options

See "Case-sensitive Options" in Data::Session for important information.

## Method: new()

Creates a new object of type Data::Session::Driver::Memcached.

`"new()"` takes a hash of key/value pairs, some of which might mandatory. Further, some combinations might be mandatory.

The keys are listed here in alphabetical order.

They are lower-case because they are (also) method names, meaning they can be called to set or get the value at any time.

- o cache =\> $object

  Specifies the object of type Cache::Memcached to use for session storage.

  This key is normally passed in as Data::Session -\> new(cache =\> `$object`).

  This key is mandatory.

- o verbose =\> $integer

  Print to STDERR more or less information.

  Typical values are 0, 1 and 2.

  This key is normally passed in as Data::Session -\> new(verbose =\> `$integer`).

  This key is optional.

## Method: remove($id)

Deletes from storage the session identified by `$id`.

Returns the result of calling the Cache::Memcached method delete($id).

This result is a Boolean value indicating 1 =\> success or 0 =\> failure.

## Method: retrieve($id)

Retrieve from storage the session identified by `$id`.

Returns the result of calling the Cache::Memcached method get($id).

This result is a frozen session. This value must be thawed by calling the appropriate serialization driver's **thaw()** method.

Data::Session calls the right **thaw()** automatically.

## Method: store($id, $data, $time)

Writes to storage the session identified by `$id`, together with its data `$data`. The expiry time of the object is passed into the **set()** method of Cache::Memcached, too.

Returns the result of calling the Cache::Memcached method set($id, `$data`, `$time`).

This result is a Boolean value indicating 1 =\> success or 0 =\> failure.

Note: `$time` is 0 for sessions which don't expire. If you wish to pass undef or 'never', as per the Cache::Memcached documentation, you will have to subclass Cache::Memcached and override the **set()** method to change 0 to 'never'.

## Method: traverse()

There is no mechanism (apart from memcached's debug code) to get a list of all keys in a cache managed by memcached, so there is no way to traverse them via this module.

Returns 1.

## Installing memcached

```
        Get libevent from http://www.monkey.org/~provos/libevent/
        I used V 2.0.8-rc
        ./configure
        make && make verify
        sudo make install
        It installs into /usr/local/lib, so tell memcached where to look:
        LD_LIBRARY_PATH=/usr/local/lib
        export LD_LIBRARY_PATH
        Get memcached from http://memcached.org/
        I used V 1.4.5
        ./configure --with-libevent=/usr/local/lib
        make && make test
        sudo make install
        Running memcached:
        memcached -m 5 &
```

## Support

Log a bug on RT: \<https://rt.cpan.org/Public/Dist/Display.html?Name=Data-Session\>.

## Author

Data::Session was written by Ron Savage *\<ron@savage.net.au\>* in 2010.

Home page: \<http://savage.net.au/index.html\>.

## Copyright

Australian copyright (c) 2010, Ron Savage.

```
        All Programs of mine are 'OSI Certified Open Source Software';
        you can redistribute them and/or modify them under the terms of
        The Artistic License, a copy of which is available at:
        http://www.opensource.org/licenses/index.html
```
