Andre Garcia Carneiro > Cache-Memcached-Queue-0.1.7 > Cache::Memcached::Queue

Download:
Cache-Memcached-Queue-0.1.7.tar.gz

Dependencies

Annotate this POD

CPAN RT

New  1
Open  0
View/Report Bugs
Module Version: 0.1.7   Source  

NAME ^

 Cache::Memcached::Queue - Simple and elegant way to persist queues on Memcached 

VERSION ^

 Version 0.1.7

 unstable version

DESCRIPTION ^

The idea is take advantage from Cache::Memcached::Fast module using it as a back-end for queue structures without sockets, extra protocols or extra databases to maintain queues-metadata. All stuff is stored on Memcached! Including metadata.

This can be done adding some metadata on Memcached hash structure that controls data on a queue structure(strict FIFO). This metadata defines identification for queues and controls first element, last element, size(number of elements) and lock information following patterns in their names. For stabilish this patterns, it's necessary to define some elements:

SYNOPSIS ^

  use common::sense;
  use Cache::Memcached::Queue;
  my $q = Cache::Memcached::Queue->new(   
          name => 'foo', 
          id => 1,
          servers => ['localhost:11211'], #This is default. RTFM ON Cache::Memcached::Fast for more options
          serialize => 1, #if true, every value on enq will be serialized (Data::Serializer with Storable)
                          #but if complex data is passed(hashes, arrays, objects, etc), this data will be
                          #serialized even serialize attribute is false.
         );  

  
  #loading queue  
  $q->load();#load data from Memcached

  #common operations...
  $q->enq('fus'); #enqueue 'fus'. 

  $q->enq('goh'); #enqueue 'goh' and this never expires on memcached 

  $q->show; #show all items from queue. In this case: 'goh'. Remember... FIFO(First In First Out).

  $q->deq; #deqeue 'fus'. 

  $q->show; #show all items from queue. In this case: 'nuke'(first and last element from queue).

  $q->enq({'fus'=>['goh','dah']}); #enqueue serialize and compact data.

  $q->cleanup; #cleans everything. From object and from Memcached.

load()

Try to load the queue metadata from Memcached. If works, will return true. Otherwise will return false.

enq( HashRef $parameters or SCALAR $value )

Try to make a 'enqueue' operation. You can enqueue scalar or complex data(hashes, arrays, objects etc).

There is two ways to enqueue:

If you try to enqueue complex data, it will be serialized. Doesn't matter if serialize attribute or parameter is set to false.

If you want to use alternative way, you must know the following valid parameters:

value - A value that presupposes that you want to save
serialize - If you need the value to be serialized, you must set serialized to true(1).

Example2: $enq({value => $some_object_or_structure, serialize => 1, });

If this work, the method will return true. Otherwise, will return false.

You can change serialize parameters setting 'serializer' method too.

deq()

Try to make a 'dequeue' operation on Queue. That means the first value of queue will be removed from queue, and the first index pointer from queue will be moved to the next index. If works, returns the 'dequeued' value, otherwise returns undef.

There is no parameters

Example:

 my $first_element_of_queue = $q->deq;

show()

Try to show the content of queue(the data). This is made finding the 'first' and 'last' pointers, extracting the sequential index, and interate the queue with this indexes, making a 'get' operation from Memcached. If the value exists, it will be showed. If not, a exception will be thrown .

There is no parameters

Example:

say $q->show;

cleanup()

Dequeue everything! No parameters! Returns true, if it's all right! Otherwise, returns false/throws an exception

save( ArrayRef $parameters )

Internal method to save the queue metadata.

iterate(CODE $action, Array $action_params)

That method is a 'handler'. You can treat all values in another subroutine/static method, passing two parameters:

So, by default, every index and values that are in your queue are passed together with your customized parameters.

If you pass everything right, your 'action' will be performed! Otherwise, an exception will be throwed.

AUTHOR ^

Andre Garcia Carneiro, <bang at cpan.org>

BUGS ^

The queue lost reference to last element when there is more than one process accessing queue. I'm working on it.

Please report any bugs or feature requests to bug-cache-memcached-queue at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Cache-memcached-Queue. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

NOTES FOR THIS VERSION ^

TODO ^

SUPPORT ^

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

  perldoc Cache::Memcached::Queue

You can also look for information at:

LICENSE AND COPYRIGHT ^

Copyright 2013 2014 Andre Garcia Carneiro.

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 http://dev.perl.org/licenses/ for more information.

syntax highlighting: