Installations
npm install @anchan828/nest-cache-manager-ioredis
Developer
anchan828
Developer Guide
Module System
CommonJS, ESM
Min. Node Version
Typescript Support
Yes
Node Version
20.18.0
NPM Version
lerna/3.10.0/node@v20.18.0+x64 (linux)
Statistics
2 Stars
1,263 Commits
4 Watching
6 Branches
2 Contributors
Updated on 28 Nov 2024
Languages
TypeScript (96.04%)
JavaScript (3.96%)
Total Downloads
Cumulative downloads
Total Downloads
165,596
Last day
-75%
1
Compared to previous day
Last week
4.8%
305
Compared to previous week
Last month
-31.7%
758
Compared to previous month
Last year
-62.2%
19,086
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dev Dependencies
1
@anchan828/nest-cache
A cache module for Nest framework (node.js) https://nestjs.com/
Installation
1$ npm i --save @anchan828/nest-cache
Quick Start
- Import module
1@Module({ 2 imports: [CacheModule.register()], 3}) 4export class AppModule {}
1@Injectable() 2export class ExampleService { 3 constructor(private readonly cacheService: CacheService) {} 4 5 private items: Item[] = Array(5) 6 .fill(0) 7 .map((_, index) => ({ id: index, name: `Item ${index}` })); 8 9 public async getItems(userId: number): Promise<Item[]> { 10 const cacheKey = `users/${userId}/items`; 11 12 const cache = await this.cacheService.get<Item[]>(cacheKey); 13 14 if (cache) { 15 return cache; 16 } 17 18 await this.cacheService.set(cacheKey, this.items); 19 20 return this.items; 21 } 22}
Middleware
You can add middleware that is executed just before calling the cache method. It can be used as an interceptor to process the cache key or the value to be stored, or to define dependencies on the cache to manipulate other caches under certain conditions.
1@Injectable() 2export class ExampleService { 3 constructor(private readonly cacheService: CacheService) {} 4 5 public async update(userId: number, age: number): Promise<void> { 6 await this.cacheService.set(`users/${userId}`, age, 10, { 7 /** 8 * You can pass information to be processed under specific conditions used in middleware. 9 */ 10 source: { userId }, 11 }); 12 } 13} 14 15@CacheMiddleware({ 16 /** 17 * The priority of the middleware. The higher the number, the low the priority. 18 */ 19 priority: 1, 20}) 21class TestCacheMiddleware implements ICacheMiddleware { 22 constructor(private readonly cacheService: CacheService) {} 23 /** 24 * If you want to set a hook for set, implement the set method. 25 */ 26 async set(context: CacheContext<"set">): Promise<void> { 27 /** 28 * Change data 29 */ 30 context.key = `version-1/${context.key}`; 31 context.value = { data: context.value }; 32 context.ttl = 1000; 33 34 /** 35 * Get the source passed from the set method 36 */ 37 const source = context.getSource<{ userId: number }>(); 38 39 /** 40 * Manage other caches under certain conditions 41 */ 42 if (source?.userId === 1) { 43 this.cacheService.delete("another-cache-key"); 44 } 45 } 46 47 /** 48 * You can define middleware for most methods. 49 */ 50 // ttl?(context: CacheContext<"ttl">): Promise<void>; 51 // delete?(context: CacheContext<"delete">): Promise<void>; 52 // mget?(context: CacheContext<"mget">): Promise<void>; 53 // mset?(context: CacheContext<"mset">): Promise<void>; 54 // mdel?(context: CacheContext<"mdel">): Promise<void>; 55 // hget?(context: CacheContext<"hget">): Promise<void>; 56 // hset?(context: CacheContext<"hset">): Promise<void>; 57 // hdel?(context: CacheContext<"hdel">): Promise<void>; 58 // hgetall?(context: CacheContext<"hgetall">): Promise<void>; 59 // hkeys?(context: CacheContext<"hkeys">): Promise<void>; 60} 61 62@Module({ 63 imports: [CacheModule.register()], 64 prividers: [ 65 /** 66 * Register middleware 67 */ 68 TestCacheMiddleware, 69 ExampleService, 70 ], 71}) 72export class AppModule {}
Using In-memory
@anchan828/nest-cache has been extended to make more Redis commands available. In line with this, the memory store also provides compatibility features. Please use @anchan828/nest-cache-manager-memory instead of the default memory store.
1import { memoryStore } from "@anchan828/nest-cache-manager-memory"; 2 3@Module({ 4 imports: [ 5 CacheModule.register({ 6 store: memoryStore, 7 }), 8 ], 9}) 10export class AppModule {}
Using Redis
You can use Redis instead of in-memory cache. Please use @anchan828/nest-cache-manager-ioredis
@anchan828/nest-cache-manager-ioredis has the ability to cache Redis results in AsyncLocalStorage. This is useful for elements that need to be accessed frequently.
1import { redisStore } from "@anchan828/nest-cache-manager-ioredis"; 2const asyncLocalStorage = new AsyncLocalStorage<Map<string, any>>(); 3@Module({ 4 imports: [ 5 CacheModule.register({ 6 store: redisStore, 7 host: "localhost", 8 asyncLocalStorage, 9 }), 10 ], 11}) 12export class AppModule {}
Supported for more Redis commands
- hget
- hset
- hdel
- hgetall
- hkeys
License
No vulnerabilities found.
Reason
30 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
0 existing vulnerabilities detected
Reason
SAST tool detected but not run on all commits
Details
- Info: SAST configuration detected: CodeQL
- Warn: 0 commits out of 27 are checked with a SAST tool
Reason
dependency not pinned by hash detected -- score normalized to 5
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:33: update your workflow using https://app.stepsecurity.io/secureworkflow/anchan828/nest-cache/codeql-analysis.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:41: update your workflow using https://app.stepsecurity.io/secureworkflow/anchan828/nest-cache/codeql-analysis.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:52: update your workflow using https://app.stepsecurity.io/secureworkflow/anchan828/nest-cache/codeql-analysis.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:66: update your workflow using https://app.stepsecurity.io/secureworkflow/anchan828/nest-cache/codeql-analysis.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/major-release.yml:10: update your workflow using https://app.stepsecurity.io/secureworkflow/anchan828/nest-cache/major-release.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/major-release.yml:13: update your workflow using https://app.stepsecurity.io/secureworkflow/anchan828/nest-cache/major-release.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/minor-release.yml:10: update your workflow using https://app.stepsecurity.io/secureworkflow/anchan828/nest-cache/minor-release.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/minor-release.yml:13: update your workflow using https://app.stepsecurity.io/secureworkflow/anchan828/nest-cache/minor-release.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/patch-release.yml:14: update your workflow using https://app.stepsecurity.io/secureworkflow/anchan828/nest-cache/patch-release.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/patch-release.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/anchan828/nest-cache/patch-release.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:14: update your workflow using https://app.stepsecurity.io/secureworkflow/anchan828/nest-cache/test.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/anchan828/nest-cache/test.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/test.yml:28: update your workflow using https://app.stepsecurity.io/secureworkflow/anchan828/nest-cache/test.yml/main?enable=pin
- Info: 0 out of 12 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 1 third-party GitHubAction dependencies pinned
- Info: 4 out of 4 npmCommand dependencies pinned
Reason
Found 0/3 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/codeql-analysis.yml:1
- Warn: no topLevel permission defined: .github/workflows/major-release.yml:1
- Warn: no topLevel permission defined: .github/workflows/minor-release.yml:1
- Warn: no topLevel permission defined: .github/workflows/patch-release.yml:1
- Warn: no topLevel permission defined: .github/workflows/test.yml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'main'
Score
5.1
/10
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More