keyv-file

Specialized in the `keyv-file` adapter for Keyv. Use this when the user needs persistent file-based storage with features like batch writing (writeDelay), TTL management (expiredCheckDelay), and the `makeField` API for direct access.

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "keyv-file" with this command: npx skills add zaaack/prompts/zaaack-prompts-keyv-file

keyv-file

keyv-file is a fast, JSON-based storage adapter for Keyv. It is specifically optimized for performance through asynchronous batch writing and automatic background cleanup of expired data.


Configuration Options

When initializing KeyvFile, you can fine-tune its behavior using the following options:

OptionDefault ValueDescription
filename${os.tmpdir()}/keyv-file/default.jsonThe path where your data is persisted.
expiredCheckDelay86400000 (24h)Interval (ms) to scan and purge expired keys from the file.
writeDelay100Delay (ms) to batch multiple write operations, reducing disk I/O.
encodeJSON.stringifyCustom serialization function.
decodeJSON.parseCustom deserialization function.

Usage Patterns

1. Standard Keyv Integration

The most common way to use it is as a store for the main Keyv instance.

const Keyv = require('keyv')
const { KeyvFile } = require('keyv-file')

const keyv = new Keyv({
  store: new KeyvFile({
    filename: './data/cache.json',
    writeDelay: 50 // Faster writes for high-frequency updates
  })
});

2. The "Field" Pattern (Direct Usage)

You can use KeyvFile directly and utilize makeField for a more declarative, type-safe API.

import KeyvFile, { makeField } from 'keyv-file'

class MyDatabase extends KeyvFile {
  constructor() {
    super({ filename: './db.json' })
  }

  // Creates a dedicated helper for a specific key
  userSettings = makeField(this, 'user_settings_key')
}

const db = new MyDatabase()
await db.userSettings.set({ theme: 'dark' })
const settings = await db.userSettings.get({ theme: 'light' }) // returns default if empty

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

General

keyv-browser

No summary provided by upstream source.

Repository SourceNeeds Review
General

nstate

No summary provided by upstream source.

Repository SourceNeeds Review
General

create-skill

No summary provided by upstream source.

Repository SourceNeeds Review
General

geo-optimizer

No summary provided by upstream source.

Repository SourceNeeds Review