# Caching — नेस्टजेएस

Source: https://www.geekswithgeeks.com/hi/nestjs/nestjs-caching

> In-memory या Redis caching से performance improve करें।

## Cache decorator

Method results को automatically cache करने के लिए `@Cacheable()` या `@Cache()` का उपयोग करें।

```typescript
import { Cacheable } from '@nestjs/cache-manager';

@Cacheable({ ttl: 300 }) // cache for 5 minutes
findAll() {
  return this.usersService.findAll();
}
```

## Redis cache

Cache store को configure करके in-memory से Redis में switch करें।

```typescript
import { CacheModule } from '@nestjs/cache-manager';
import type { RedisClientOptions } from 'redis';

CacheModule.register<RedisClientOptions>({
  isGlobal: true,
  store: 'redis',
  host: 'localhost',
  port: 6379
})
```
