CHI-Driver-LMDB

 view release on metacpan or  search on metacpan

lib/CHI/Driver/LMDB.pm  view on Meta::CPAN

Default is C<0>

  tx_flags => 0 # no flags

=head2 C<put_flags>

Flags to pass to C<< ->put(k,v,WRITE_FLAGS) >>.

See L<< LMDB_File->put options|LMDB_File/LMDB_File >> for details.

=head2 C<mapsize>

Passes through to C<< LMDB::Env->new( mapsize => ... ) >>

Default value is taken from L</cache_size> with some C<m/k> math if its set.

=head2 C<maxreaders>

Passes through to C<< LMDB::Env->new( maxreaders => ... ) >>

=head2 C<maxdbs>

Passes through to C<< LMDB::Env->new( maxdbs => ... ) >>

Defines how many CHI namespaces ( Databases ) a path can contain.

Default is 1024.

=head2 C<mode>

Passes through to C<< LMDB::Env->new( mode => ... ) >>

Defines the permissions on created DB Objects.

Defaults to C<oct 600> == C<-rw------->

=head2 C<flags>

Passes through to C<< LMDB::Env->new( flags => ... ) >>

=head1 PERFORMANCE

If write performance is a little slow for you ( due to the defaults being a single
transaction per SET/GET operation, and transactions being flushed to disk when written ),
there are two ways you can make performance a little speedy.

=head2 Single Transaction Mode.

If you pass C<< single_txn => 1 >> the cache will be given a single transaction
for the life of its existence. However, pay attention to the warnings about cleaning
up properly in L</single_txn>.

Also, this mode is less ideal if you want to have two processes sharing a cache,
because the data won't be visible on the other one till it exits! ☺

=head2 C<NOSYNC> Mode.

You can also tell LMDB B<NOT> to call C<sync> at the end of every transaction,
and this will greatly improve write performance due to IO being greatly delayed.

This greatly weakens the databases consistency, but that seems like a respectable
compromise for a mere cache backend, where a missing record is a performance hit, not a loss of data.

  use LMDB_File qw( MDB_NOSYNC MDB_NOMETASYNC );
  ...
  my $cache = CHI->new(
    ...
    flags => MDB_NOSYNC | MDB_NOMETASYNC
  );

This for me cuts down an operation that takes 30 seconds worth of writes down to 6 ☺.

=head1 In Depth

For an in-depth comparison of the performance of various options,
and how that compares to L<< C<CHI::Driver::FastMmap>|CHI::Driver::FastMmap >>,
see L<< http://kentnl.github.io/CHI-Driver-LMDB >>

=for Pod::Coverage BUILD DEMOLISH clear fetch fetch_multi_hashref get_keys get_namespaces max_key_length remove store store_multi

=head1 AUTHOR

Kent Fredric <kentnl@cpan.org>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2017 by Kent Fredric <kentfredric@gmail.com>.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

=cut



( run in 1.524 second using v1.01-cache-2.11-cpan-98e64b0badf )