keyv-file
Original:🇺🇸 English
Translated
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.
2installs
Sourcezaaack/prompts
Added on
NPX Install
npx skill4agent add zaaack/prompts keyv-fileTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →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 , you can fine-tune its behavior using the following options:
KeyvFile| Option | Default Value | Description |
|---|---|---|
| | The path where your data is persisted. |
| | Interval (ms) to scan and purge expired keys from the file. |
| | Delay (ms) to batch multiple write operations, reducing disk I/O. |
| | Custom serialization function. |
| | Custom deserialization function. |
Usage Patterns
1. Standard Keyv Integration
The most common way to use it is as a store for the main Keyv instance.
javascript
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 directly and utilize for a more declarative, type-safe API.
KeyvFilemakeFieldtypescript
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