Skip to content

Commit 1a2b5e6

Browse files
committed
Initial commit
0 parents  commit 1a2b5e6

File tree

12 files changed

+4112
-0
lines changed

12 files changed

+4112
-0
lines changed

.LICENSE

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
MIT License
2+
3+
This extension is developed and maintained by Forte Digital. For more information about our products and services, visit [our website](https://fortedigital.com).
4+
5+
Copyright (c) 2024 Forte_ Digital and Arseny Kruglikov
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy
8+
of this software and associated documentation files (the "Software"), to deal
9+
in the Software without restriction, including without limitation the rights
10+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the Software is
12+
furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in all
15+
copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
SOFTWARE.

README.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# @fortedigital/nextjs-cache-handler
2+
3+
This package extends the functionality of [`@neshca/cache-handler`](https://www.npmjs.com/package/@neshca/cache-handler) by providing additional cache handlers for specialized use cases, specifically for Redis-based caching solutions. The original `@neshca/cache-handler` offers a robust caching API for Next.js applications, and this package introduces two new handlers for managing Redis cache with different expiration strategies and tag-based revalidation.
4+
5+
## Installation
6+
7+
To install this package along with its dependencies:
8+
9+
```bash
10+
npm install @fortedigital/nextjs-cache-handler
11+
```
12+
13+
Ensure that you have already set up `@neshca/cache-handler` before integrating these extended handlers.
14+
15+
## Handlers
16+
17+
### 1. `redis-strings`
18+
19+
This handler is designed to manage cache operations using Redis strings. It supports key-based and tag-based caching with flexible expiration strategies.
20+
21+
#### Features:
22+
23+
- **Key Expiration Strategy**: Choose between `EXAT` (more efficient with Redis 6.2 or newer) or `EXPIREAT` (compatible with Redis 4.0 or newer).
24+
- **Tag-based Revalidation**: Supports cache revalidation using tags for efficient and fine-grained cache invalidation.
25+
- **TTL Management**: Automatically manages time-to-live (TTL) for cache keys and tags.
26+
27+
#### Usage:
28+
29+
```js
30+
const redisHandler = await createHandler({
31+
client, // Redis client instance
32+
keyPrefix: "myApp:",
33+
sharedTagsKey: "myTags",
34+
sharedTagsTtlKey: "myTagTtls",
35+
});
36+
```
37+
38+
### 2. `composite`
39+
40+
The composite handler allows for managing cache operations using a combination of other handlers. It provides a flexible way to route cache operations to multiple underlying handlers based on a defined strategy.
41+
42+
#### Features:
43+
44+
- **Flexible Handling**: Supports multiple handlers, enabling complex caching strategies.
45+
- **Custom Set Strategy**: Allows you to define how cache entries are routed to different handlers.
46+
- **On-Demand Revalidation**: Retrieves values from the first available handler, ensuring efficient data access.
47+
48+
#### Usage:
49+
50+
```js
51+
const compositeHandler = createHandler({
52+
handlers: [handler1, handler2], // Array of underlying handlers
53+
setStrategy: (data) => (data?.tags.includes("handler1") ? 0 : 1),
54+
});
55+
```
56+
57+
## Reference to Original Package
58+
59+
This package builds upon the core functionality provided by [`@neshca/cache-handler`](https://www.npmjs.com/package/@neshca/cache-handler). You can find more information about the core library, including usage examples and API documentation, at the [official documentation page](https://caching-tools.github.io/next-shared-cache).
60+
61+
## License
62+
63+
This project is licensed under the [MIT License](./LICENSE), as is the original `@neshca/cache-handler` package.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
.vscode
4+
5+
# dependencies
6+
/node_modules
7+
/studio/node_modules
8+
/.pnp
9+
.pnp.js
10+
11+
# production
12+
/dist
13+
14+
# misc
15+
.DS_Store
16+
*.pem
17+
.vscode
18+
19+
# debug
20+
npm-debug.log*
21+
yarn-debug.log*
22+
yarn-error.log*
23+
.pnpm-debug.log*
24+
25+
# IntelliJ
26+
.idea
27+
*.iml
28+
29+
# typescript
30+
*.tsbuildinfo
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export const endOfLine = "crlf";
2+
export const printWidth = 100;
3+
export const tabWidth = 4;
4+
export const useTabs = false;
5+
export const singleQuote = false;
6+
export const semi = true;
7+
export const trailingComma = "all";
8+
export const bracketSpacing = true;
9+
export const bracketSameLine = false;
10+
export const arrowParens = "always";
11+
export const quoteProps = "as-needed";
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"parser": "@typescript-eslint/parser",
3+
"extends": [
4+
"eslint:recommended",
5+
"plugin:@typescript-eslint/recommended",
6+
"prettier"
7+
],
8+
"plugins": ["@typescript-eslint", "simple-import-sort"],
9+
"rules": {
10+
"@typescript-eslint/no-unused-vars": ["error"],
11+
"array-callback-return": "warn",
12+
"eqeqeq": "warn",
13+
"func-style": [
14+
"warn",
15+
"declaration",
16+
{
17+
"allowArrowFunctions": true
18+
}
19+
],
20+
"import/first": "warn",
21+
"import/newline-after-import": "warn",
22+
"import/no-duplicates": "warn",
23+
"multiline-comment-style": ["warn", "starred-block"],
24+
"no-lonely-if": "warn",
25+
"no-self-compare": "error",
26+
"no-template-curly-in-string": "error",
27+
"no-unreachable-loop": "warn",
28+
"no-unused-expressions": "warn",
29+
"no-unused-vars": "off",
30+
"no-var": "error",
31+
"prefer-arrow-callback": "warn",
32+
"prefer-const": "warn",
33+
"prefer-promise-reject-errors": "warn",
34+
"prefer-spread": "warn",
35+
"simple-import-sort/exports": "warn",
36+
"simple-import-sort/imports": "warn"
37+
},
38+
"root": true
39+
}

0 commit comments

Comments
 (0)