Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mateonunez/orama-cache
This plugin provides a cache system for Orama. The cache system is based on async-cache-dedupe.
https://github.com/mateonunez/orama-cache
async-cache-dedupe cache lyra memory nodejs orama plugin redis
Last synced: 10 days ago
JSON representation
This plugin provides a cache system for Orama. The cache system is based on async-cache-dedupe.
- Host: GitHub
- URL: https://github.com/mateonunez/orama-cache
- Owner: mateonunez
- License: mit
- Created: 2022-10-20T16:31:02.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-04-23T18:28:28.000Z (7 months ago)
- Last Synced: 2024-05-06T12:26:39.403Z (6 months ago)
- Topics: async-cache-dedupe, cache, lyra, memory, nodejs, orama, plugin, redis
- Language: TypeScript
- Homepage:
- Size: 2.17 MB
- Stars: 13
- Watchers: 3
- Forks: 0
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# โจ๐จ Orama Cache
This plugin provides a cache system for [Orama](https://github.com/oramasearch/orama). The cache system is based on [async-cache-dedupe](https://github.com/mcollina/async-cache-dedupe).
[![Tests](https://github.com/mateonunez/orama-cache/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/mateonunez/orama-cache/actions/workflows/ci.yml)
## ๐ Getting Started
### ๐ฆ Installation
```bash
# You can install Orama using `npm`, `yarn`, `pnpm`:
npm install orama-cache
```### ๐ Usage
> Example using the default storage (memory)
```js
import { create, insert } from "@orama/orama"
import { createOramaCache } from "orama-cache"(async() => {
const db = create({ schema: { name: "string" } })await insert(db, { name: "foo" })
await insert(db, { name: "bar" })const cache = await createOramaCache(db) // Create the cache.
const results = await cache.search({ term: "foo" }) // This method will return the results and cache them.
// ...
const cachedResults = await cache.search({ term: "foo" }) // Returns the cached results.
})()```
## ๐ Documentation
You can use the same APIs as [async-cache-dedupe](https://github.com/mcollina/async-cache-dedupe#api).
> Example using Redis as storage
```js
const oramaCache = createOramaCache({
storage: {
type: 'redis',
options: {
client: new Redis(),
invalidation: {
invalidates: true,
referencesTTL: 60 // seconds
}
}
}
})
```## ๐ Benchmarks
Some searches can be ~2K faster using a cache system.
```js
{
elapsedTime: '81ms',
fetchRes: {
elapsed: 81312667n,
hits: [
[Object], [Object],
[Object], [Object],
[Object], [Object],
[Object], [Object],
[Object], [Object]
],
count: 100000
}
}
// Cached result, same searched `term`
{
elapsedTimeCached: '40ฮผs',
fetchCached: {
elapsed: 81312667n,
hits: [
[Object], [Object],
[Object], [Object],
[Object], [Object],
[Object], [Object],
[Object], [Object]
],
count: 100000
}
}
```### โ Results
The `orama-cache` plugin provides a set of benchmarks to compare the performance of the cache system with the default search.
```bash
npm run benchmark
``````bash
# Resultsโโโโโโโโโโโโโโโโโโโโโโโโคโโโโโโโโโโคโโโโโโโโโโโโโโโโโโโคโโโโโโโโโโโโคโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Slower tests โ Samples โ Result โ Tolerance โ Difference with slowest โ
โโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโข
โ Orama search โ 30000 โ 184233.47 op/sec โ ยฑ 1.53 % โ โ
โโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโข
โ Fastest test โ Samples โ Result โ Tolerance โ Difference with slowest โ
โโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโข
โ Orama caching search โ 30000 โ 596449.98 op/sec โ ยฑ 1.91 % โ + 223.75 % โ
โโโโโโโโโโโโโโโโโโโโโโโโงโโโโโโโโโโงโโโโโโโโโโโโโโโโโโโงโโโโโโโโโโโโงโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโคโโโโโโโโโโคโโโโโโโโโโโโโโโโโโโคโโโโโโโโโโโโคโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Slower tests โ Samples โ Result โ Tolerance โ Difference with slowest โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโข
โ Orama search with properties โ 30000 โ 208403.59 op/sec โ ยฑ 1.40 % โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโข
โ Fastest test โ Samples โ Result โ Tolerance โ Difference with slowest โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโข
โ Orama caching search with properties โ 30000 โ 524996.42 op/sec โ ยฑ 2.40 % โ + 151.91 % โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโงโโโโโโโโโโงโโโโโโโโโโโโโโโโโโโงโโโโโโโโโโโโงโโโโโโโโโโโโโโโโโโโโโโโโโโ
```## โ ๏ธ Testing
To run the tests you should run the following commands:
```bash
npm run redis
```That command shall start a new Redis istance using Docker. Then run the tests.
```bash
npm run test
```## ๐ License
[MIT](/LICENSE)