The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.


Dancer::Plugin::Memcached - Cache response content to memcached


This plugin gives Dancer the ability to get and store page content in a memcached server, which in specific configurations could give a performance boost - particulary on GET requests that incur significant database calls.

In your configuration, a list of servers with port numbers needs to be defined.

            - ""
        - ""
            default_timeout: 86400

The default_timeout specifies an fallback time for keys to expire from the cache. If this value is less than 60*60*24*30 (30 days), time is assumed to be seconds after the key was stored. If larger, it's considered an absolute Unix time.

In your package:

    package MyWebService;
    use Dancer;
    use Dancer::Plugin::Memcached;

    get '/' sub => {
        # Do your logic here
        memcached_set template($foo);

This plugin will use the PATH_INFO environment variable to store as the key so routes that make use of parameters in the form of "/foo/:bar" will be cached, but GET/POST variables will not.



Will check for any route and return the page stored in memcached where available.

memcached_set($content, [$expiration])

For any given content, set and return the content. Expiration time for the set can optionally be set.


Grab a specified key. Returns false if the key is not found.

memcached_store($key, $content, [$expiration])

This keyword is identical to memcached_set with the exception that you can set any key name.


Squeeks, <squeek at>


Zefram, <>


Please report any bugs or feature requests to bug-dancer-plugin-memcached at, or through the web interface at I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.


You can find documentation for this module with the perldoc command.

    perldoc Dancer::Plugin::Memcached

You can also look for information at:


Dancer Web Framework - Dancer


Copyright 2013 Squeeks.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See for more information.