NAME

PAGI::FastAPI::Queue::Driver::Memory - Default In-Memory Storage Driver for PAGI::FastAPI::Queue

VERSION

Version v1.2.5

SYNOPSIS

use PAGI::FastAPI::Queue::Driver::Memory;

my $driver = PAGI::FastAPI::Queue::Driver::Memory->new;

$driver->push('emails', { to => 'a@b.com' })->get;
my $item = $driver->pop('emails')->get;
my $count = $driver->size('emails')->get;

# Memory-driver-specific extension (not part of the base Driver contract)
$driver->clear('emails');  # empty a single topic
$driver->clear;            # empty every topic

DESCRIPTION

PAGI::FastAPI::Queue::Driver::Memory is the standard implementation of PAGI::FastAPI::Queue::Driver. It comes with the core PAGI::FastAPI package and is utilised directly by PAGI::FastAPI::Queue unless another driver is used.

All messages of a certain topic are stored as an array in an in-process hash table; push adds a message and pop removes it in FIFO order.

Note: Everything happens entirely in process memory and is kept private to the driver instance. Messages in queue are not accessible from outside, that is from other processes (e.g. Starman, Hypnotoad) or different instances of PAGI::FastAPI::Queue::Driver::Memory. Use distributed storage driver (e.g. Redis or SQS) in production.

METHODS

Inherits push, pop, and size from PAGI::FastAPI::Queue::Driver.

new()

Instantiates a new in-memory queue driver. Takes no required arguments.

push($topic, $payload)

Appends $payload (any scalar) to the end of $topic. Returns a Future resolving to 1.

pop($topic)

Removes and returns a Future resolving to the item at the front of $topic, or undef if $topic is empty or has never been pushed to.

size($topic = undef)

Returns a Future resolving to the number of pending items in $topic, or 0 if unknown/empty. If $topic is omitted (or undef), resolves to the sum of pending items across every topic.

clear($topic = undef)

Memory-driver-specific extension, not part of the base PAGI::FastAPI::Queue::Driver contract and not exposed through PAGI::FastAPI::Queue. Empties $topic if given, or every topic if omitted. Returns $self for chaining. Synchronous (does not return a Future).

SEE ALSO

PAGI::FastAPI::Queue::Driver, PAGI::FastAPI::Queue

AUTHOR

Mohammad Sajid Anwar, <mohammad.anwar at yahoo.com>

REPOSITORY

https://github.com/manwar/PAGI-FastAPI

BUGS

Please report any bugs or feature requests through the web interface at https://github.com/manwar/PAGI-FastAPI/issues. I will be notified and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

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

perldoc PAGI::FastAPI::Queue::Driver::Memory

You can also look for information at:

LICENSE AND COPYRIGHT

Copyright (C) 2026 Mohammad Sajid Anwar.

This program is free software; you can redistribute it and/or modify it under the terms of the Artistic License (2.0).