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

NAME

GX::Cache::Memcached - Base class for Memcached-based cache components

SYNOPSIS

    package MyApp::Cache::Default;
    
    use GX::Cache::Memcached;
    
    __PACKAGE__->setup(
        servers => [ '127.0.0.1:11211' ]
    );
    
    1;

DESCRIPTION

This module provides the GX::Cache::Memcached class which extends the GX::Cache class.

METHODS

Constructor

new

Returns the cache component instance.

    $cache = $cache_class->new;
Returns:
Exceptions:

Public Methods

All public methods can be called both as instance and class methods.

add

Like set(), but only stores the given value if the key does not already exist.

    $result = $cache->add( $key, $value );
    $result = $cache->add( $key, $value, $expire_time );
Arguments:
  • $key ( string )

  • $value ( scalar )

  • $expire_time ( integer ) [ optional ]

Returns:
  • $result ( bool )

clear

Clears the cache.

    $cache->clear;

get

Retrieves the value(s) for the given key(s).

    $value = $cache->get( $key );
Arguments:
  • $key ( string )

Returns:
  • $value ( scalar )

    @values = $cache->get( @keys );
Arguments:
  • @keys ( strings )

Returns:
  • @values ( scalars )

If get() is called with more than one key but in scalar context, it returns a reference to a hash with the retrieved key / value pairs.

    $pairs = $cache->get( @keys );
Arguments:
  • @keys ( strings )

Returns:
  • $pairs ( HASH reference )

memcached

Returns the associated Cache::Memcached instance.

    $memcached = $cache->memcached;
Returns:

namespace

Returns the namespace key prefix.

    $namespace = $cache->namespace;
Returns:
  • $namespace ( string | undef )

options

Returns a list with the additional options that are passed to the Cache::Memcached constructor.

    %options = $cache->options;
Returns:
  • %options ( named list )

remove

Removes the specified key / value pair. Returns true if the pair was actually stored and successfully removed, otherwise false.

    $result = $cache->remove( $key );
Arguments:
  • $key ( string )

Returns:
  • $result ( bool )

replace

Like set(), but only stores the given value if the key already exists.

    $result = $cache->replace( $key, $value );
    $result = $cache->replace( $key, $value, $expire_time );
Arguments:
  • $key ( string )

  • $value ( scalar )

  • $expire_time ( integer ) [ optional ]

Returns:
  • $result ( bool )

servers

Returns a list with the memcached server addresses.

    @servers = $cache->servers;
Returns:
  • @servers ( strings )

set

Unconditionally sets the specified key to the given value. Returns true on success, otherwise false.

    $result = $cache->set( $key, $value );
    $result = $cache->set( $key, $value, $expire_time );
Arguments:
  • $key ( string )

  • $value ( scalar )

  • $expire_time ( integer ) [ optional ]

Returns:
  • $result ( bool )

setup

Sets up the component.

    $cache->setup( %options );
Options:
  • namespace ( string | undef )

    A key prefix. Defaults to the class name of the component.

  • options ( HASH reference )

    Additional options for the Cache::Memcached constructor.

  • servers ( ARRAY reference )

    A list of memcached server addresses. Defaults to a single address: "127.0.0.1:11211".

Exceptions:

SEE ALSO

AUTHOR

Jörg A. Uzarek <uzarek@runlevelnull.de>

COPYRIGHT AND LICENSE

Copyright (c) 2009-2011 Jörg A. Uzarek.

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