NAME

Data::RecordStore - Simple store for text and byte data

SYNPOSIS

use Data::RecordStore;

$store = Data::RecordStore->init_store( DIRECTORY => $directory, MAX_FILE_SIZE => 20_000_000_000 );
$data = "TEXT OR BYTES";

# the first record id is 1
my $id = $store->stow( $data );

my $val = $store->fetch( $some_id );

my $count = $store->entry_count;

$store->lock( qw( FEE FIE FOE FUM ) ); # lock blocks, may not be called until unlock.

$store->unlock; # unlocks all

$store->delete_record( $id_to_remove ); #deletes the old record

$reopened_store = Data::RecordStore->open_store( $directory );

DESCRIPTION

Data::RecordStore is a simple way to store serialized text or byte data. It is written entirely in perl with no non-core dependencies. It is designed to be both easy to set up and easy to use.

It adheres to a RecordStore interface so other implementations exist using other technologies rather than simple binary file storage.

Transactions (see below) can be created that stow records. They come with the standard commit and rollback methods. If a process dies in the middle of a commit or rollback, the operation can be reattempted. Incomplete transactions are obtained by the store's 'list_transactions' method.

Data::RecordStore operates directly and instantly on the file system. It is not a daemon or server and is not thread safe. It can be used in a thread safe manner if the controlling program uses locking mechanisms, including the locks that the store provides.

METHODS

open_store( options )

Constructs a data store according to the options.

Options

BASE_PATH
MIN_FILE_SIZE - default is 4096
MAX_FILE_SIZE - default is 2 gigs

reopen_store( directory )

Opens the existing store in the given directory.

fetch( id )

Returns the record associated with the ID. If the ID has no record associated with it, undef is returned.

stow( data, optionalID )

This saves the text or byte data to the record store. If an id is passed in, this saves the data to the record for that id, overwriting what was there. If an id is not passed in, it creates a new record store.

Returns the id of the record written to.

next_id

This sets up a new empty record and returns the id for it.

delete_record( id )

Removes the entry with the given id from the store, freeing up its space. It does not reuse the id.

lock( @names )

Adds an advisory (flock) lock for each of the unique names given. This may not be called twice in a row without an unlock in between and will die if that happens.

unlock

Unlocks all names locked by this thread

use_transaction()

Returns the current transaction. If there is no current transaction, it creates one and returns it.

commit_transaction()

Commits the current transaction, if any.

rollback_transaction()

Rolls back the current transaction, if any.

entry_count

Returns how many record ids exist.

index_silo

Returns the index silo for this store. This method is not part of the record store interface.

max_file_size

Returns the max file size of any silo in bytes. This method is not part of the record store interface.

silos

Returns a list of data silo objects where the data silo record size is 2**index position. This means that the beginning of the list will have undefs as there is a minimum silo size. This method is not part of the record store interface.

transaction_silo

Returns the transaction silo for this store. This method is not part of the record store interface.

active_entry_count

Returns how many record ids exist that have silo entries. This method is not part of the record store interface.

silos_entry_count

Returns the number of entries in the data silos.

detect_version( $dir )

Tries to detect the version of the Data::RecordStore in the given directory, if any.

AUTHOR Eric Wolf coyocanid@gmail.com

COPYRIGHT AND LICENSE

Copyright (c) 2015-2020 Eric Wolf. All rights reserved.
This program is free software; you can redistribute it
and/or modify it under the same terms as Perl itself.

VERSION Version 6.05 (Jan, 2020))

1 POD Error

The following errors were encountered while parsing the POD:

Around line 698:

You forgot a '=back' before '=head2'