Gathering detailed insights and metrics for @anchan828/nest-cache-manager-ioredis
Gathering detailed insights and metrics for @anchan828/nest-cache-manager-ioredis
Gathering detailed insights and metrics for @anchan828/nest-cache-manager-ioredis
Gathering detailed insights and metrics for @anchan828/nest-cache-manager-ioredis
npm install @anchan828/nest-cache-manager-ioredis
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
2 Stars
1,263 Commits
4 Watching
6 Branches
2 Contributors
Updated on 28 Nov 2024
TypeScript (96.04%)
JavaScript (3.96%)
Cumulative downloads
Total Downloads
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
1
A cache module for Nest framework (node.js) https://nestjs.com/
1$ npm i --save @anchan828/nest-cache
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}
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 {}
@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 {}
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 {}
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
Reason
0 existing vulnerabilities detected
Reason
SAST tool detected but not run on all commits
Details
Reason
dependency not pinned by hash detected -- score normalized to 5
Details
Reason
Found 0/3 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Score
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