https://github.com/timmikeladze/keyv-arango
ArangoDB store for Keyv: simple key-value storage with support for multiple backends.
https://github.com/timmikeladze/keyv-arango
arango arangodb cache key-value key-value-store keyv keyvaluestore storage
Last synced: about 2 months ago
JSON representation
ArangoDB store for Keyv: simple key-value storage with support for multiple backends.
- Host: GitHub
- URL: https://github.com/timmikeladze/keyv-arango
- Owner: TimMikeladze
- License: mit
- Created: 2022-12-13T03:24:26.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2023-04-17T15:18:17.000Z (about 2 years ago)
- Last Synced: 2025-03-30T20:51:22.016Z (about 2 months ago)
- Topics: arango, arangodb, cache, key-value, key-value-store, keyv, keyvaluestore, storage
- Language: TypeScript
- Homepage:
- Size: 31.3 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
Awesome Lists containing this project
README
# keyv-arango
[ArangoDB](https://github.com/arangodb/arangodb) store for [Keyv](https://github.com/jaredwray/keyv): simple key-value storage with support for multiple backends.
## Install
```shell
npm install keyv-arango keyv arangojs
# or
yarn add keyv-arango keyv arangojs
# or
pnpm add keyv-arango keyv arangojs
```## Usage
```ts
import Keyv from 'keyv'
import { KeyvArango, KeyvArangoOptions } from 'keyv-arango'const options: KeyvArangoOptions = {
// An ArangoDB database config object. This field is required.
// If no database is specified, the default `_system` database will be used.
config: {
url: process.env.ARANGO_URL
},
// All fields below are optional.
cacheCollection: true, // whether to cache the collection instance in between data calls. Defaults to true.
collectionName: 'keyv', // the name of the collection to use. Defaults to 'keyv'.
expireAfter: 0, // how long to wait before expiring a key (in milliseconds). Defaults to 0.
field: 'expireDate', // the name of the field which will store the expiration date. Defaults to 'expireDate'.
namespace: null // the keyv namespace to use. Defaults to null.
}const store = new KeyvArango(options)
const keyv = new Keyv({ store })
// From here on, you can use keyv as usual.
await keyv.set('foo', 'bar', 1000)
await keyv.get('foo')
```## ArangoDB and TTL Indexes
When using TTL indexes in ArangoDB is no guarantee that a key will be deleted at the exact time specified, only that the key will be deleted. ArangoDB runs a background thread which is responsible for cleaning up keys. The frequency of this thread is configurable, but **defaults to 30 seconds**.
This is an important caveat to keep in mind when using this library and ArangoDB in general. **Without prior configuration, ArangoDB is not suitable for short-lived keys.** When starting an ArangoDB instance the `--ttl.frequency` option can be used to configure the frequency of the background thread. For more information, see the [ArangoDB documentation](https://www.arangodb.com/docs/stable/programs-arangod-options.html#ttl-frequency). In fact the CI tests for this library use a frequency of 1 second to ensure that the tests pass in a timely manner.