Cache-Memcached-Managed
view release on metacpan or search on metacpan
lib/Cache/Memcached/Managed.pm view on Meta::CPAN
dedicated to keeping a directory of data kept in the L<"data server">.
The group concept allows you to associate a given L<"data key"> to a named
group and an group ID value (e.g. the group named "group" and the name of an
SQL table). This information is then stored in the L<"directory server">,
from which it is possible to obtain a list of L<"data keys"> associated with
the group name and the ID value.
In the current implementation, the only one group name is recognized by
default:
=over 2
=item group
Intended for generic data without specific keys.
=back
You can specify your own set of group names with the "group_names"
parameter in L<new>.
Group names and ID's can be specified with each of the L<add>, L<decr>,
L<incr>, L<replace> and L<set> to indicate the link with the group of the
information being cached.
The pseudo group ID 'C<:key>' can be specified to indicate that the key
should be used for the group ID. This is usually used in conjunction with
the generic 'C<group>' group name
A list of valid group names can be obtained with the L<group_names> method.
=head2 directory server
The directory server is a Cache::Memcached (compatible) object that is being
used to store L<"data key">s (as opposed to the data itself) used in
L<"group management">. If no L<directory> server was specified, then the
data server will be assumed.
If there are multiple memcached servers used for the L<"data server">, then
it is advised to use a separate directory server (as a failure in one of
the memcached backend servers will leave you with an incomplete directory
otherwise).
Should the directory server fail, and it is vital that there is no stale data
in the data server, then a L<flush_all> would need to be executed to ensure
that no stale data remains behind. Of course, this will also delete all
non-stale data from the data server, so your mileage may vary.
=head2 expiration specification
Expiration can be specified in seconds, but, for convenience, can also be
specified in days, hours and minutes (and seconds). This is indicated by
a number, immediately followed by a letter B<D> (for days) or B<H> (for hours)
or B<M> (for minutes) or B<S> (for seconds). For example:
2D3H
means 2 days and 3 hours, which means B<183600> seconds.
=head2 transparent fork handling
Using this module, you do not have to worry if everything will still work
after a fork(). As soon as it is detected that the process has forked, new
handles will be opened to the memcached servers in the child process (so the
meticulous calling of "disconnect_all" of L<Cache::Memcached> is no longer
needed).
Transparent thread handling is still on the todo list.
=head1 CLASS METHODS
=head2 new
my $cache = Cache::Memcached::Managed->new;
my $cache = Cache::Memcached::Managed->new( '127.0.0.1:11311' );
my $cache = Cache::Memcached::Managed->new(
data => '127.0.0.1:11311', # default: '127.0.0.1:11211'
directory => '127.0.0.1:11411', # default: data
delimiter => ';', # default: '#'
expiration => '1H', # default: '1D'
flush_interval => 10, # default: none
namespace => 'foo', # default: $> ($EUID)
group_names => [qw(foo bar)], # default: ['group']
memcached_class => 'Cached::Memcached::Fast', # default: 'Cache::Memcached'
);
my $cache = Cache::Memcached::Managed->new( inactive => 1 );
Create a new Cache::Memcached::Managed object. If there are less than two
input parameters, then the input parameter is assumed to be the value of
the "data" field, with a default of '127.0.0.1:11211'. If there are more
than one input parameter, the parameters are assumed to be a hash with the
following fields:
=over 2
=item data
data => '127.0.0.1:11211,127.0.0.1:11212',
data => ['127.0.0.1:11211','127.0.0.1:11212'],
data => {
servers => ['127.0.0.1:11211','127.0.0.1:11212'],
debug => 1,
},
data => $memcached,
The specification of the memcached server backend(s) for the L<"data server">.
It should either be:
- string with comma separated memcached server specification
- list ref with memcached server specification
- hash ref with Cache::Memcached object specification
- blessed object adhering to the Cache::Memcached API
( run in 2.352 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )