- A note of warning
- SEE ALSO
- COPYRIGHT AND LICENSE
Maplat::Web::MemCache - Module for access to memcached
This is a wrapper around Cache::Memcache (and similar) with a few addons.
This module provides a web module 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.
If you want to store data permanent (even within a single program run), you should use Maplat::Web::MemCachePg, which is using this module, but also uses the PostgreSQL module as a permanent backing store.
The memcache daemon itself is very fast, but is basically a cache; e.g. if more data comes in that it can hold, the oldest data is silently discarded. Therefore, using a backing store for things like Login-data, shopping cart contents and other things you want to permanently store, use a real backing store. You dont want to loose some session information because more users logged on than memcached was set to handle.
A few Maplat::Web:: modules implement their own caching strategy, like the UserSettings module. For these, you should *not* use Maplat::Web::MemCachePg but Maplat::Web::MemCache, otherwise you negate some of the performance due to overhead (double store).
<module> <modname>memcache</modname> <pm>MemCache</pm> <options> <service>127.0.0.1:11211</service> <namespace>RBSMem</namespace> <viewcommands> <view>Adm Worker</view> <view>Other Worker</view> </viewcommands> </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.
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
must be accesible and hold reasonable values.
viewcommands is a list of workers that can work on the commandqueue table. This helps checking every worker for active commands and highlighting them in various other modules
Refresh the lifetick variable for this application in memcached.
Disable lifetick handling.
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.
Read data from memcached. Takes one argument, the key name, returns a reference to the data from memcached or undef.
Delete a key from memcached. Takes one argument, the key name, returns a boolean indicating success or failure.
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.
Returns a hash with all currently active commands in all (configured) workers, webguis and other apps.
Internal function to reconnect to the memcache daemon after forking.
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.
This module is a basic module which does not depend on other web modules.
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).
Rene Schickbauer, <email@example.com>
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.