Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .coderabbit.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
language: "en-US"
language: 'en-US'
early_access: false
reviews:
profile: "assertive"
profile: 'assertive'
request_changes_workflow: false
high_level_summary: true
poem: false
Expand All @@ -13,4 +13,4 @@ reviews:
enabled: true
drafts: false
chat:
auto_reply: true
auto_reply: true
4 changes: 2 additions & 2 deletions .devcontainer/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ services:
volumes:
- redis-data:/data
healthcheck:
test: ["CMD-SHELL", "redis-cli ping | grep PONG"]
test: ['CMD-SHELL', 'redis-cli ping | grep PONG']
interval: 5s
timeout: 5s
retries: 5
Expand All @@ -45,4 +45,4 @@ services:
ports:
- 5540:5540
volumes:
- redis-insight:/data
- redis-insight:/data
4 changes: 2 additions & 2 deletions .github/workflows/build-and-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Check out repository code
uses: actions/checkout@v5

- name: Install system dependencies
- name: Install system dependencies
run: |
apt-get update
apt-get install -y unzip
Expand All @@ -35,4 +35,4 @@ jobs:
- name: Test
env:
REDIS_URL: redis://redis:6379
run: bun run test
run: bun run test
9 changes: 3 additions & 6 deletions .github/workflows/publish-package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Check out repository code
uses: actions/checkout@v5

- name: Install system dependencies
- name: Install system dependencies
run: |
apt-get update
apt-get install -y unzip
Expand All @@ -41,15 +41,12 @@ jobs:
REDIS_URL: redis://redis:6379
run: bun run test

- name: Copy extra files
run: cp ./README.md ./LICENSE ./packages/cache

- name: Publish package to NPM
env:
NPM_CONFIG_TOKEN: ${{ secrets.NPM_CONFIG_TOKEN }}
run: cd ./packages/cache && bun publish --tolerate-republish --access public
run: bun publish --tolerate-republish --access public

- name: Publish package to GitHub
env:
NPM_CONFIG_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: cd ./packages/cache && bun publish --tolerate-republish --access public --registry https://npm.pkg.github.com
run: bun publish --tolerate-republish --access public --registry https://npm.pkg.github.com
File renamed without changes.
6 changes: 3 additions & 3 deletions .oxfmtrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"insertFinalNewline": true,
"jsxSingleQuote": true,
"trailingComma": "all",
"ignorePatterns": [
"ignorePatterns": [
"**/dist/*",
"**/.next/*",
"**/.turbo/*",
Expand All @@ -21,5 +21,5 @@
"apps/next/src/app/(payload)/*",
"apps/start/.wrangler/*",
"apps/start/src/routeTree.gen.ts"
],
}
]
}
22 changes: 5 additions & 17 deletions .oxlintrc.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
{
"$schema": "./node_modules/oxlint/configuration_schema.json",
"plugins": [
"typescript",
"react"
],
"plugins": ["typescript", "react"],
"categories": {
"correctness": "warn",
"pedantic": "warn",
Expand Down Expand Up @@ -105,9 +102,7 @@
],
"overrides": [
{
"files": [
"**/*.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"
],
"files": ["**/*.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"],
"rules": {
"for-direction": "error",
"no-async-promise-executor": "error",
Expand Down Expand Up @@ -165,9 +160,7 @@
}
},
{
"files": [
"**/*.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"
],
"files": ["**/*.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"],
"env": {
"browser": true,
"commonjs": true,
Expand All @@ -176,12 +169,7 @@
}
},
{
"files": [
"**/*.ts",
"**/*.tsx",
"**/*.mts",
"**/*.cts"
],
"files": ["**/*.ts", "**/*.tsx", "**/*.mts", "**/*.cts"],
"rules": {
"no-class-assign": "off",
"no-const-assign": "off",
Expand All @@ -202,4 +190,4 @@
}
}
]
}
}
2 changes: 1 addition & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
"vitest.explorer",
"zenstack.zenstack-v3"
]
}
}
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"typescript.experimental.useTsgo": true,
"[javascript][javascriptreact][typescript][typescriptreact][json][jsonc]": {
"editor.defaultFormatter": "oxc.oxc-vscode"
},
}
}
33 changes: 18 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
ZenStack Cache
</h1>

Reduce response times and database load with query-level caching integrated with the ZenStack ORM.
Reduce response times and database load with query-level caching integrated with the ZenStack ORM.

</div>

<div align="center">
Expand All @@ -19,7 +20,7 @@
<a href="https://discord.gg/2PaRSu7X">
<img alt="Join the ZenStack Cache channel" src="https://img.shields.io/discord/1035538056146595961">
</a>
<a href="https://github.com/visualbravo/zenstack-cache/blob/76a2de03245c26841b04525dd8b424a8799d654c/LICENSE">
<a href="https://github.com/visualbravo/zenstack-cache/blob/dev/LICENSE">
<img alt="License: MIT" src="https://img.shields.io/badge/license-MIT-green">
</a>

Expand All @@ -29,17 +30,18 @@
</div>

## Features
* 🌐 **Redis Cache:** A central cache to scale across different systems.
* 🖥️ **Memory Cache:** A simple cache when scale is not a concern.
* 🛟 **Type-safety:** The caching options appear in the intellisense for all read queries.
* 🏷️ **Tag-based Invalidation:** Easily invalidate multiple related cache entries.

- 🌐 **Redis Cache:** A central cache to scale across different systems.
- 🖥️ **Memory Cache:** A simple cache when scale is not a concern.
- 🛟 **Type-safety:** The caching options appear in the intellisense for all read queries.
- 🏷️ **Tag-based Invalidation:** Easily invalidate multiple related cache entries.

## Requirements

* ZenStack (version >= `3.3.0`)
* Node.js (version >= `20.0.0`)
* Redis (version >= `7.0.0`)
* ℹ️ Only if you intend to use the `RedisCacheProvider`
- ZenStack (version >= `3.3.0`)
- Node.js (version >= `20.0.0`)
- Redis (version >= `7.0.0`)
- ℹ️ Only if you intend to use the `RedisCacheProvider`

## Installation

Expand Down Expand Up @@ -115,21 +117,22 @@ After performing a query, you can check where the result came from.
const publishedPostsStatus = client.$cache.status // 'hit' | 'miss' | 'stale'
```

* `hit` - a cache entry in the `ttl` window was found, and the database was not queried.
* `miss` - a cache entry was not found, and the database was queried.
* `stale` - a cache entry in the `swr` window was found, and the database was queried in the background to revalidate it.
- `hit` - a cache entry in the `ttl` window was found, and the database was not queried.
- `miss` - a cache entry was not found, and the database was queried.
- `stale` - a cache entry in the `swr` window was found, and the database was queried in the background to revalidate it.

## Revalidation

If the result was stale, you can choose to await its revalidation.

```typescript
const revalidatedPublishedPosts = await client.$cache.revalidation as Post[]
```

## Cache Options

* `ttl` reduces response times and database load by serving cached results.
* `swr` reduces response times by serving cached results, but does not reduce database load because it performs a revalidation in the background after each request.
- `ttl` reduces response times and database load by serving cached results.
- `swr` reduces response times by serving cached results, but does not reduce database load because it performs a revalidation in the background after each request.

> [!NOTE]
> The total TTL of a cache entry is equal to its `ttl` + `swr`. The `ttl` window comes first, followed by the `swr` window. You can combine the two options to best suit the needs of your application.
Expand Down
61 changes: 11 additions & 50 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading