Beta . Ortha CMS is in public beta. Every plan is free until it ends.
Features Ortha CMS on GitHub

In-memory storage

Media plugin @orthacms/media-server@orthacms/media-admin

For the test harness and offline development. Never for a deployment.

Documents 0.13.1 Updated Edit this page Report a problem

On this page

An in-memory StorageProvider: blobs in a Map, plus three inspection methods. Published, unlike the copilot’s scripted model.

  • id: memory
  • Capabilities: { directUrl: false, contentTypeMetadata: true, streamingPut: false }

Not for a deployment

Blobs die with the process. On the next boot, the storage check refuses the database, because its rows point at bytes that are gone.

Install and register

npm install --save-dev @orthacms/media-provider-memory
import { createMemoryStorageProvider } from '@orthacms/media-provider-memory';

export const storage = createMemoryStorageProvider({
    maxTotalBytes: 64 * 1024 * 1024 // default 256 MB
});

MediaServerPlugin({
    provider: storage,
    config: { directServe: 'off', maxUploadBytes: 10 * 1024 * 1024 }
});

No environment variables. MemoryStorageConfig is { maxTotalBytes? }.

Inspect it in a test

MethodReturns
keys()Every stored key, sorted
totalBytes()Current size
clear()Empties the store
afterEach(() => storage.clear());

it('stores the original and its derivatives', async () => {
    const asset = await uploadFixture('kingfisher.jpg');

    expect(storage.keys()).toEqual([
        `${workspaceId}/${asset.id}/kingfisher.jpg`,
        `${workspaceId}/${asset.id}/variants/preview.webp`,
        `${workspaceId}/${asset.id}/variants/thumb.webp`
    ]);
});

it('removes the blobs when the asset is deleted', async () => {
    const asset = await uploadFixture('kingfisher.jpg');
    await deleteAssets([asset.id]);
    expect(storage.totalBytes()).toBe(0);
});

uploadFixture and deleteAssets stand for your own helpers around POST /api/media/assets and DELETE /api/media/assets.

Behaviour worth knowing

  • MemoryStoreFullError when a put would exceed maxTotalBytes, so a runaway test fails as a test, not an out-of-memory kill.
  • put buffers (streamingPut: false): nothing reaches the Map until the body has fully arrived, so a failed body leaves the store unchanged.
  • Keys match the local provider’s layout, so assertions can be shared.
  • It passes the same contract suite as every other backend.