Trove
1.x
Docs/Trove/Memory Driver
Open

Reading2 min
Updated31 Jul 2026
Sourcev1/storage/drivers/memory.mdx

The memory driver stores all objects in-memory using Go maps protected by a read-write mutex. It is designed for testing and development -- data is lost when the process exits.

Installation01

go get github.com/xraph/trove/drivers/memdriver

Usage02

import (
    "github.com/xraph/trove"
    "github.com/xraph/trove/drivers/memdriver"
)

drv := memdriver.New()

t, err := trove.Open(drv)
if err != nil {
    log.Fatal(err)
}
defer t.Close(ctx)

No DSN or Open() call is required -- the memory driver is ready to use immediately after New().

DSN Format03

When used via DSN-based resolution (e.g., in multi-store configuration), the memory driver uses the mem:// scheme:

storage_driver: "mem://"

Driver Registry04

The memory driver registers itself in the global driver registry under the mem scheme. This enables DSN-based driver resolution in multi-store mode:

import _ "github.com/xraph/trove/drivers/memdriver" // registers "mem"

Features05

  • Thread-safe -- All operations are protected by sync.RWMutex

  • Zero configuration -- No DSN, no files, no setup

  • Sorted listing -- List returns objects in lexicographic key order

  • Pagination -- Supports WithMaxKeys and cursor-based pagination

  • Full conformance -- Passes the complete trovetest.RunDriverSuite

When to Use06

  • Unit tests -- Fast, isolated test environments with no filesystem dependencies

  • Integration tests -- Verify routing and multi-backend logic without real backends

  • Development -- Quick prototyping without setting up storage infrastructure

  • Conformance testing -- Reference implementation for the driver interface

  • Multi-store scratch space -- Ephemeral store alongside persistent stores in multi-store mode

Example: Test Setup07

func TestMyService(t *testing.T) {
    drv := memdriver.New()
    store, _ := trove.Open(drv)
    defer store.Close(context.Background())

    store.CreateBucket(context.Background(), "test")

    // Your test logic using store...
}

Example: Multi-Backend Testing08

func TestRouting(t *testing.T) {
    primary := memdriver.New()
    archive := memdriver.New()

    store, _ := trove.Open(primary,
        trove.WithBackend("archive", archive),
        trove.WithRoute("*.log", "archive"),
    )

    // Put a .log file -- routes to archive
    store.Put(ctx, "logs", "app.log", strings.NewReader("log data"))

    // Verify it landed on the archive driver
    _, err := archive.Get(ctx, "logs", "app.log")
    assert.NoError(t, err)
}

Limitations09

  • Data is not persisted -- lost on process exit

  • No multipart upload, pre-signed URLs, versioning, or lifecycle management

  • Not suitable for production use with large datasets (all data is in memory)