2.0.75 • Published 2 days ago

@anchan828/nest-cache v2.0.75

Weekly downloads
-
License
MIT
Repository
github
Last release
2 days ago

@anchan828/nest-cache

npm NPM

A cache module for Nest framework (node.js) https://nestjs.com/

Installation

$ npm i --save @anchan828/nest-cache

Quick Start

  • Import module
@Module({
  imports: [CacheModule.register()],
})
export class AppModule {}
@Injectable()
export class ExampleService {
  constructor(private readonly cacheService: CacheService) {}

  private items: Item[] = Array(5)
    .fill(0)
    .map((_, index) => ({ id: index, name: `Item ${index}` }));

  public async getItems(userId: number): Promise<Item[]> {
    const cacheKey = `users/${userId}/items`;

    const cache = await this.cacheService.get<Item[]>(cacheKey);

    if (cache) {
      return cache;
    }

    await this.cacheService.set(cacheKey, this.items);

    return this.items;
  }
}

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.

import { memoryStore } from "@anchan828/nest-cache-manager-memory";

@Module({
  imports: [
    CacheModule.register({
      store: memoryStore,
    }),
  ],
})
export 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.

import { redisStore } from "@anchan828/nest-cache-manager-ioredis";
const asyncLocalStorage = new AsyncLocalStorage<Map<string, any>>();
@Module({
  imports: [
    CacheModule.register({
      store: redisStore,
      host: "localhost",
      asyncLocalStorage,
    }),
  ],
})
export class AppModule {}

Supported for more Redis commands

  • hget
  • hset
  • hdel
  • hgetall
  • hkeys

License

MIT

2.0.75

2 days ago

2.0.74

9 days ago

2.0.73

16 days ago

2.0.72

23 days ago

2.0.71

1 month ago

2.0.70

1 month ago

2.0.69

1 month ago

2.0.68

2 months ago

2.0.67

2 months ago

2.0.66

2 months ago

2.0.65

2 months ago

2.0.64

3 months ago

2.0.63

3 months ago

2.0.62

3 months ago

2.0.61

3 months ago

2.0.60

4 months ago

2.0.59

4 months ago

2.0.58

5 months ago

2.0.57

5 months ago

2.0.55

5 months ago

2.0.56

5 months ago

2.0.53

6 months ago

2.0.54

6 months ago

2.0.52

6 months ago

2.0.51

6 months ago

2.0.37

10 months ago

2.0.38

9 months ago

2.0.35

10 months ago

2.0.36

10 months ago

2.0.34

10 months ago

2.0.39

9 months ago

2.0.48

7 months ago

2.0.49

7 months ago

2.0.46

8 months ago

2.0.47

7 months ago

2.0.44

8 months ago

2.0.45

8 months ago

2.0.42

8 months ago

2.0.43

8 months ago

2.0.40

9 months ago

2.0.41

9 months ago

2.0.50

7 months ago

2.0.33

11 months ago

2.0.31

11 months ago

2.0.32

11 months ago

2.0.30

12 months ago

2.0.28

1 year ago

2.0.29

12 months ago

2.0.27

1 year ago

2.0.19

1 year ago

2.0.18

1 year ago

2.0.26

1 year ago

2.0.24

1 year ago

2.0.25

1 year ago

2.0.22

1 year ago

2.0.23

1 year ago

2.0.20

1 year ago

2.0.21

1 year ago

2.0.15

1 year ago

2.0.16

1 year ago

2.0.14

1 year ago

2.0.17

1 year ago

2.0.3

2 years ago

2.0.2

2 years ago

2.0.13

1 year ago

2.0.5

2 years ago

2.0.4

2 years ago

2.0.11

1 year ago

2.0.7

1 year ago

2.0.12

1 year ago

2.0.6

2 years ago

2.0.9

1 year ago

2.0.10

1 year ago

2.0.8

1 year ago

2.0.1

2 years ago

2.0.0

2 years ago

1.2.11

2 years ago

1.2.8

2 years ago

1.2.7

2 years ago

1.2.6

2 years ago

1.2.5

2 years ago

1.2.4

2 years ago

1.2.9

2 years ago

1.2.10

2 years ago

1.2.3

2 years ago

1.2.2

2 years ago

1.2.1

2 years ago

1.2.0

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.12.5

2 years ago

0.12.4

2 years ago

0.12.3

2 years ago

0.12.2

2 years ago

0.12.1

2 years ago

0.12.0

2 years ago

0.11.14

2 years ago

0.11.13

2 years ago