Storage

Using Vercube StorageManager backed by Nitro's built-in storage

The Nitro integration replaces the default StorageManager with NitroStorageManager, which delegates all operations to Nitro's built-in useStorage() API. Your controllers use the same StorageManager interface - no code changes needed.

Configuration

Storage drivers are configured in nitro.config.ts, not at runtime. The standard StorageManager.mount() method is not supported and will log a warning if called.

nitro.config.ts
import { vercubeNitro } from '@vercube/nitro';
import { defineConfig } from 'nitro';

export default defineConfig({
  modules: [vercubeNitro()],
  storage: {
    cache: {
      driver: 'redis',
      url: process.env.REDIS_URL,
    },
  },
});

Using Storage in a Controller

Inject StorageManager exactly as you would in a standalone Vercube app:

src/routes/CacheController.ts
import { Controller, Get, Param } from '@vercube/core';
import { Inject } from '@vercube/di';
import { StorageManager } from '@vercube/storage';

@Controller('/api/cache')
export class CacheController {

  @Inject(StorageManager)
  private storage: StorageManager;

  @Get('/:key')
  async get(@Param('key') key: string) {
    const value = await this.storage.getItem<string>({ key });
    return { key, value };
  }

  @Get('/set/:key/:value')
  async set(@Param('key') key: string, @Param('value') value: string) {
    await this.storage.setItem({ key, value });
    return { key, value };
  }
}

Named Storage

Pass the storage option to target a named storage defined in nitro.config.ts:

// Read from the 'cache' storage
const value = await this.storage.getItem<string>({ storage: 'cache', key: 'foo' });

// Write to the 'cache' storage
await this.storage.setItem({ storage: 'cache', key: 'foo', value: 'bar' });

If the named storage doesn't exist, Nitro's default storage is used as a fallback.

Supported Operations

MethodSupport
getItem
getItems
setItem
deleteItem
hasItem
getKeys
clear
size⚠️ Always returns 0
mount❌ Not supported - use nitro.config.ts
Previous

File-Based Routes

Mixing Nitro file-based routes with Vercube controllers

Next