The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Maplat::Worker::MemCache - Module for access to memcached

SYNOPSIS

This is a wrapper around Cache::Memcache (and similar) with a few addons.

DESCRIPTION

This module provides a Worker modules that gives the caller an interface to the memcached service. Internally, it tries to use (in that order) Cache::Memcached::Fast, Cache::Memcached and Maplat::Helpers::Cache::Memcached and test if they actually can set and retrieve keys.

Configuration

        <module>
                <modname>memcache</modname>
                <pm>MemCache</pm>
                <options>
                        <service>127.0.0.1:11211</service>
                        <namespace>MyMaplat</namespace>
                </options>
        </module>

service is IP address and port of the memcached service

namespace if a single name assigned to all programs of the same project. Different projects accessing the same memcached server must use different namespaces, while all programs working on a common project must use the same namespace. this is so, because next to caching, memcached in the Maplat framework is also used for interprocess communication.

maxage is the maximum age in days the files are allowed to reside in the directory

Further, the main script must declare the variables $VERSION and $APPNAME, because some functionality of the wrapper needs those. This values are set in memcached and can be read out by the WebGUI as a central point of determing which versions and build of which program are running on the server. So, the variables

  $main::APPNAME
  $main::VERSION

must be accesible and hold reasonable values.

refresh_lifetick

Refresh the lifetick variable for this application in memcached.

disable_lifetick

Temporarly disables lifetick handling for this application. To resume, just call refresh_lifetick once more.

set

Save data in memcached.

Takes two arguments, a key name and a reference to the data to be stored in memcached. Returns a boolean to indicate success or failure.

get

Read data from memcached. Takes one argument, the key name, returns a reference to the data from memcached or undef.

delete

Delete a key from memcached. Takes one argument, the key name, returns a boolean indicating success or failure.

set_activecommand

Sets the command currently processed by this application (or 0 to indicate no active command). Takes one argument, the id of the currently active command. Returns a boolean indicating success or failure.

sanitize_key

Internal function to sanitize (clean up and re-encode) the memcached key string. Memcached has some limitations how the keys can be named, this functions is used on every access to memcached to make sure the keys adhere to this restrictions.

Dependencies

This module is a basic module which does not depend on other worker modules.

A note of warning

Memcache caches data between runs of Maplat. If you're upgrading Maplat or changing some data structures you want to save/retrieve with Memcache, you should restart your memcached daemon.

Otherwise, expect some unexpected results (aka the "WTF is going on" effect).

SEE ALSO

Maplat::Worker

AUTHOR

Rene Schickbauer, <rene.schickbauer@gmail.com>

COPYRIGHT AND LICENSE

Copyright (C) 2008-2011 by Rene Schickbauer

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.0 or, at your option, any later version of Perl 5 you may have available.