<commit_before>=head1 NAME

Bio::JBrowse::HashStore - on-disk 2-level hash table

=head1 DESCRIPTION

Makes an on-disk hash table, designed to be easily read as static files over HTTP.

Makes a set of JSON-encoded files at paths based on a hash of the key.
For example:

  path/to/dir/29c/c14/fc
  path/to/dir/23f/5ad/11
  path/to/dir/711/7c1/29
  path/to/dir/5ec/b24/6a
  path/to/dir/4de/9ac/c6
  path/to/dir/41b/c43/27
  path/to/dir/28c/d86/e9

Where each file contains a JSON object containing data items like:

  { foo: "bar", ... }

Where "foo" is the original key, and "bar" is the JSON-encoded data.

=cut

package Bio::JBrowse::HashStore;
use strict;
use warnings;

use JSON 2;

use File::Spec ();
use File::Path ();

use Tie::Cache::LRU ();

=head2 open( dir => "/path/to/dir" )

=cut

sub open {
    my $class = shift;

    my $self = bless { @_ }, $class;
    File::Path::mkpath( $self->{dir} );

    tie %{$self->{cache} = {}}, 'Tie::Cache::LRU', 500;

    return $self;<commit_msg>don't need to cache more than 50 hash buckets in a perl HashStore<commit_after>=head1 NAME

Bio::JBrowse::HashStore - on-disk 2-level hash table

=head1 DESCRIPTION

Makes an on-disk hash table, designed to be easily read as static files over HTTP.

Makes a set of JSON-encoded files at paths based on a hash of the key.
For example:

  path/to/dir/29c/c14/fc
  path/to/dir/23f/5ad/11
  path/to/dir/711/7c1/29
  path/to/dir/5ec/b24/6a
  path/to/dir/4de/9ac/c6
  path/to/dir/41b/c43/27
  path/to/dir/28c/d86/e9

Where each file contains a JSON object containing data items like:

  { foo: "bar", ... }

Where "foo" is the original key, and "bar" is the JSON-encoded data.

=cut

package Bio::JBrowse::HashStore;
use strict;
use warnings;

use JSON 2;

use File::Spec ();
use File::Path ();

use Tie::Cache::LRU ();

=head2 open( dir => "/path/to/dir" )

=cut

sub open {
    my $class = shift;

    my $self = bless { @_ }, $class;
    File::Path::mkpath( $self->{dir} );

    tie %{$self->{cache} = {}}, 'Tie::Cache::LRU', 50;

    return $self;
{'fraction_non_alphanumeric': 0.15056400196174596, 'fraction_numerical': 0.04168710152035311, 'mean_word_length': 3.2236024844720497, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5197497', 'n_tokens_mistral': 853, 'n_tokens_neox': 782, 'n_words': 233}