NAME

BusyBird::StatusStorage::Memory - Simple status storage in the process memory

SYNOPSIS

use BusyBird::StatusStorage::Memory;

## The statuses are stored in the process memory.
my $storage = BusyBird::StatusStorage::Memory->new();

## Load statuses from a file
$storage->load("my_statuses.json");

## Save the content of the storage into a file
$storage->save("my_statuses.json");

DESCRIPTION

This module is an implementation of BusyBird::StatusStorage.

This storage stores all statuses in the process memory. The stored statuses can be saved to a file in JSON format. The saved statuses can be loaded from the file.

This storage is rather for testing purposes. If you want a light-weight in-memory status storage, I recommend BusyBird::StatusStorage::SQLite.

This storage is synchronous, i.e., all operations block the thread and the callback is called before the method returns.

This module uses BusyBird::Log for logging.

CAVEATS

  • Because this storage stores statuses in the process memory, forked servers cannot share the storage.

  • Because this storage stores statuses in the process memory, the stored statuses are lost when the process is terminated.

CLASS METHODS

$storage = BusyBird::StatusStorage::Memory->new(%options)

Creates the storage object.

You can specify the folowing options in %options.

max_status_num => MAX_STATUS_NUM (optional, default: 2000)

Specifies the maximum number of statuses the storage can store per timeline. If more statuses are added to a full timeline, the oldest statuses in the timeline are removed automatically.

OBJECTS METHODS

In addition to the following methods, all methods described in BusyBird::StatusStorage are supported, too.

$is_success = $storage->save($filepath)

Saves the current content of the storage to the file named $filepath.

In success, it returns true. In failure, it returns false and the error will be logged.

$is_success = $storage->load($filepath)

Loads statuses from the file named $filepath.

In success, it returns true. In failure, it returns false and the error will be logged.

AUTHOR

Toshio Ito <toshioito [at] cpan.org>