Stig Palmquist
and 1 contributors

NAME

Cache::Memcached::Sweet - sugary memcached with callbacks

SYNOPSIS

  # Reads MEMCACHED_HOST from env, and defaults to localhost:11211 if not set

  use Cache::Memcached::Sweet; # exports the subroutine "memcached"

  my $value = memcached($key, sub { 
        return some_expensive_operation($foo, $bar, $baz);
  });

  my $value = memcached($key); # retrieve value

  memcached($other_key, { a => 1, b => 2 }, 600); # set value with TTL

FUNCTIONS

Cache::Memcached::Sweet implements and exports the following function

memcached

  # Set's a value with no TTL
  memcached('foo', $cache_this);

  # Sets a value, with optional ttl
  memcached('bar', { a => 1, b => 2 }, 600);

  # Retrieves a value from the cache
  my $value = memcached('baz');

  # Gets a value if it exists or sets it with the return value from executing the coderef
  # Note: The coderef is called in scalar context
  my $result = memcached('blurgh', sub { 
     buzz($blirp, $blurp) 
  });

  my $mc = memcached; # Exposes package global instance of Cache::Memcached
  $mc->set_servers()  # ... etc, but not recommended
  

CAUTION

This module is meant to provide convenience, and is hardcoded to get the memcached server address from MEMCACHED_HOST or will default to localhost:11211. If you're running some fancy memcached cluster, then this module is probably not for you.

AUTHOR

Stig Palmquist, <stig at stig.io>

BUGS

https://github.com/pqx/cache-memcached-sweet

LICENSE AND COPYRIGHT

Copyright 2013 pqx Limited.

This program is distributed under the MIT (X11) License: http://www.opensource.org/licenses/mit-license.php

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.