Skip to content

Commit 62a3cc3

Browse files
committed
feat: First commit
1 parent 8e17b07 commit 62a3cc3

File tree

8 files changed

+269
-206
lines changed

8 files changed

+269
-206
lines changed

.releaserc

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,6 @@
88
"@semantic-release/npm",
99
"@semantic-release/changelog",
1010
"@semantic-release/git",
11-
"@semantic-release/github",
12-
[
13-
"@codedependant/semantic-release-docker",
14-
{
15-
"dockerTags": [
16-
"latest",
17-
"{{version}}",
18-
"{{major}}",
19-
"{{major}}.{{minor}}"
20-
],
21-
"dockerLogin": false,
22-
"dockerRegistry": "ghcr.io",
23-
"dockerProject": "tomerh2001",
24-
"dockerArgs": {
25-
"GH_REPO": "{{env.GH_REPO}}"
26-
}
27-
}
28-
],
29-
[
30-
"@codedependant/semantic-release-docker",
31-
{
32-
"dockerTags": [
33-
"latest",
34-
"{{version}}",
35-
"{{major}}",
36-
"{{major}}.{{minor}}"
37-
],
38-
"dockerProject": "tomerh2001"
39-
}
40-
]
11+
"@semantic-release/github"
4112
]
4213
}

.xo-config.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"extends": [
3+
"plugin:th-rules/recommended-typescript"
4+
]
5+
}

CHANGELOG.md

Lines changed: 0 additions & 142 deletions
This file was deleted.

Dockerfile

Lines changed: 0 additions & 8 deletions
This file was deleted.

README.md

Lines changed: 116 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,116 @@
1-
# Semantic Release Repo Template
2-
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
3-
[![XO code style](https://shields.io/badge/code_style-5ed9c7?logo=xo&labelColor=gray)](https://github.com/xojs/xo)
4-
[![Snyk Security](../../actions/workflows/snyk-security.yml/badge.svg)](../../actions/workflows/snyk-security.yml)
5-
[![CodeQL](../../actions/workflows/codeql.yml/badge.svg)](../../actions/workflows/codeql.yml)
6-
[![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/tomerh2001/semantic-release-repo-template/badge)](https://securityscorecards.dev/viewer/?uri=github.com/tomerh2001/semantic-release-repo-template)
7-
8-
# Configuration
9-
> [!NOTE]
10-
> Go to [Repository Secrets](../../settings/secrets/actions) settings and add the following:
11-
12-
| Name | Description | Required |
13-
| ------------------------- | ------------------------------------------ | -------- |
14-
| GH_TOKEN | Github Token | Yes |
15-
| NPM_TOKEN | NPM Token for publishing to NPM from CI/CD | Recommended |
16-
| CODECOV_TOKEN | Codecov Token for coverage tests | Recommended |
17-
| SNYK_TOKEN | Snyk Token for security tests | Recommended |
18-
| DOCKER_REGISTRY_USER | Docker registry user | Optional |
19-
| DOCKER_REGISTRY_PASSWORD | Docker registry password | Optional
1+
# cache-manager-function
2+
3+
`cache-manager-function` is a vertical integration library that extends `cache-manager` to provide easy-to-use function-level caching with support for Redis and other stores. It allows you to cache function results with decorators, automatic cache initialization, and customizable cache key selection strategies.
4+
5+
## Features
6+
7+
- **Function Caching**: Easily cache async functions to improve performance.
8+
- **Class Method Caching**: Use decorators to add caching to class methods.
9+
- **Custom Key Selection**: Dynamically generate cache keys using functions, strings, or paths.
10+
- **TTL Management**: Set cache expiration times to keep your data fresh.
11+
- **Seamless Integration**: Built on top of `cache-manager` for reliable and configurable caching.
12+
13+
## Installation
14+
15+
```shell
16+
npm install cache-manager-function cache-manager cache-manager-redis-store
17+
```
18+
19+
## Usage
20+
21+
### 1. Initialize Cache Manager
22+
23+
Before using caching, initialize the cache manager with your desired configuration. By default, it uses Redis as the cache store.
24+
25+
```typescript
26+
import { initializeCache } from 'cache-manager-function';
27+
28+
await initializeCache({
29+
host: 'localhost',
30+
port: 6379,
31+
ttl: 60, // Time-to-live in seconds
32+
});
33+
```
34+
35+
### 2. Caching Functions with `cacheFunction`
36+
37+
Wrap your async functions with `cacheFunction` to automatically cache their results.
38+
39+
```typescript
40+
import { cacheFunction } from 'cache-manager-function';
41+
42+
async function fetchData(id) {
43+
// Fetch data logic
44+
}
45+
46+
const cachedFetchData = cacheFunction(fetchData, {
47+
ttl: 120,
48+
keySelector: ['id'],
49+
});
50+
51+
const result = await cachedFetchData(123);
52+
```
53+
54+
### 3. Using `@cache` Decorator for Class Methods
55+
56+
Use the `@cache` decorator to cache class methods with customizable TTL and key selection.
57+
58+
```typescript
59+
import { cache } from 'cache-manager-function';
60+
61+
class DataService {
62+
@cache({ ttl: 180, keySelector: 'id' })
63+
async getData(id) {
64+
// Fetch data logic
65+
}
66+
}
67+
68+
const service = new DataService();
69+
const data = await service.getData(123);
70+
```
71+
72+
### 4. Using `@cacheMeta` for Metadata
73+
74+
The `@cacheMeta` decorator sets up metadata for caching, specifying how cache keys and TTLs are handled. This metadata can be used by other mechanisms to manage caching behavior.
75+
76+
```typescript
77+
import { cacheMeta } from 'cache-manager-function';
78+
79+
class UserService {
80+
@cacheMeta({ ttl: 60, keySelector: ['userId'] })
81+
async getUser(userId) {
82+
// Method logic
83+
}
84+
}
85+
```
86+
87+
## API
88+
89+
### `initializeCache(config: CacheInitializationConfig): Promise<void>`
90+
91+
Initializes the cache manager with the specified configuration.
92+
93+
- **config**: Configuration object with optional `host`, `port`, `password`, and required `ttl`.
94+
95+
### `cacheFunction(function_, options): Function`
96+
97+
Wraps and caches an async function based on the provided options.
98+
99+
- **function_**: The function to be cached.
100+
- **options**: Configuration options including `ttl` and `keySelector`.
101+
102+
### `@cache(options: CacheOptions)`
103+
104+
A decorator to cache class methods.
105+
106+
- **options**: Configuration object with `ttl` and `keySelector`.
107+
108+
### `@cacheMeta(options: CacheOptions)`
109+
110+
Adds caching metadata to methods for defining cache keys and TTL without direct caching.
111+
112+
- **options**: Configuration object with `ttl` and `keySelector`.
113+
114+
## License
115+
116+
This library is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.

bun.lockb

100644100755
73.3 KB
Binary file not shown.

package.json

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,31 @@
11
{
22
"name": "semantic-release-repo-template",
3+
"version": "1.0.0",
34
"module": "index.ts",
45
"type": "module",
56
"devDependencies": {
6-
"@codedependant/semantic-release-docker": "^5.0.0",
7+
"@codedependant/semantic-release-docker": "^5.0.3",
78
"@semantic-release/changelog": "^6.0.3",
89
"@semantic-release/commit-analyzer": "^13.0.0",
910
"@semantic-release/git": "^10.0.1",
10-
"@semantic-release/github": "^10.0.0",
11-
"@semantic-release/npm": "^12.0.0",
12-
"@semantic-release/release-notes-generator": "^14.0.0",
11+
"@semantic-release/github": "^10.3.2",
12+
"@semantic-release/npm": "^12.0.1",
13+
"@semantic-release/release-notes-generator": "^14.0.1",
14+
"@types/lodash": "^4.17.7",
1315
"bun-types": "latest",
14-
"xo": "^0.59.0"
16+
"xo": "^0.59.3"
1517
},
1618
"peerDependencies": {
17-
"typescript": "^5.0.0"
19+
"typescript": "^5.5.4"
1820
},
19-
"version": "1.7.0",
2021
"scripts": {
2122
"test": "xo"
23+
},
24+
"dependencies": {
25+
"cache-manager": "^5.7.6",
26+
"cache-manager-redis-store": "^3.0.1",
27+
"eslint-plugin-th-rules": "^1.13.4",
28+
"lodash": "^4.17.21",
29+
"reflect-metadata": "^0.2.2"
2230
}
2331
}

0 commit comments

Comments
 (0)