Skip to the content.

FilePersistanceProvider

A generic file-based cache provider using cacache for persistent storage.

import { FilePersistanceProvider } from "@nodesecure/cache";

interface MyData {
  name: string;
  value: number;
}

const cache = new FilePersistanceProvider<MyData>("my-cache-key");

// Store data
await cache.set({ name: "example", value: 42 });

// Retrieve data
const data = await cache.get();
console.log(data); // { name: "example", value: 42 }

// Remove data
await cache.remove();

Interfaces

interface BasePersistanceProvider<T> {
  get(): Promise<T | null>;
  set(value: T): Promise<boolean>;
  remove(): Promise<void>;
}

API

static PATH

The base path for the cache storage.

Default: os.tmpdir()/nsecure-cli

constructor(cacheKey: string)

Creates a new instance of the persistence provider.

Parameters:

get(): Promise<T | null>

Retrieves a cached value by its key.

Returns:

set(value: T): Promise<boolean>

Stores a value in the cache.

Parameters:

Returns:

remove(): Promise<void>

Removes the cached entry associated with the key.