---
name: "Catmandu::Store::Hash"
section: "3pm"
platform: "linux"
package: "libcatmandu-perl"
version: "1.2024-1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/Catmandu::Store::Hash"
---

# Catmandu::Store::Hash(3pm)

An in-memory store

## NAME

Catmandu::Store::Hash - An in-memory store

## SYNOPSIS

```
   use Catmandu;
   my $store = Catmandu->store('Hash');
   my $obj1 = $store->bag->add({ name => 'Patrick' });
   printf "obj1 stored as %s\n" , $obj1->{_id};
   # Force an id in the store
   my $obj2 = $store->bag->add({ _id => 'test123' , name => 'Nicolas' });
   my $obj3 = $store->bag->get('test123');
   $store->bag->delete('test123');
   $store->bag->delete_all;
   # All bags are iterators
   $store->bag->each(sub { ... });
   $store->bag->take(10)->each(sub { ... });
```

## DESCRIPTION

A Catmandu::Store::Hash is an in-memory Catmandu::Store backed by a hash for fast retrieval combined with a doubly linked list for fast traversal.

## METHODS

### new(\[init\_data =\> \[...\] \])

Create a new Catmandu::Store::Hash. Optionally provide as init\_data an array ref of data:

```
    my $store = Catmandu->store('Hash', init_data => [
           { _id => 1, data => foo } ,
           { _id => 2, data => bar }
    ]);
    # or in a catmandu.yml configuration file:
    ---
    store:
       hash:
         package: Hash
         options:
            init_data:
               - _id: 1
                 data: foo
               - _id: 2
                 data: bar
```

## INHERITED METHODS

This Catmandu::Store implements:

- Catmandu::Store

  - Catmandu::Droppable

  - Catmandu::Transactional

  Each Catmandu::Bag in this Catmandu::Store implements:

- Catmandu::Bag

  - Catmandu::Droppable
