Mojo::MemoryMap - Safely use anonymous memory mapped segments
use Mojo::MemoryMap; my $map = Mojo::MemoryMap->new(4096); say $map->usage; $map->writer->store({foo => 123}); say $map->writer->fetch->{foo}; say $map->writer->change(sub { delete $_->{foo} }); say $map->usage;
Mojo::MemoryMap uses File::Map to allow you to safely cache mutable data structures in anonymous mapped memory segments, and share it between multiple processes.
Mojo::MemoryMap inherits all methods from Mojo::Base and implements the following new ones.
my $map = Mojo::MemoryMap->new; my $map = Mojo::MemoryMap->new(4096);
Construct a new Mojo::MemoryMap object, defaults to a "size" of 52428800 bytes (50 MiB).
52428800
my $size = $map->size;
Size of anonymous memory segment in bytes.
my $usage = $map->usage;
Current usage of anonymous memory segment in bytes.
my $writer = $map->writer;
Acquire exclusive lock and return Mojo::MemoryMap::Writer object. Allowing the shared data structure to be retrieved and modified safely. The lock is released when the writer object is destroyed.
# Retrieve data my $data = $map->writer->fetch; # Modify data safely my $writer = $map->writer; my $data = $writer->fetch; $data->{foo} += 23; $writer->store($data); undef $writer; # Modify data safely (with less code) $map->writer->change(sub { $_->{foo} += 23 });
Mojolicious::Plugin::Status, Mojolicious::Guides, https://mojolicious.org.
To install Mojolicious::Plugin::Status, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mojolicious::Plugin::Status
CPAN shell
perl -MCPAN -e shell install Mojolicious::Plugin::Status
For more information on module installation, please visit the detailed CPAN module installation guide.