I'm trying to set up Redis caching
for my nestjs
-graphql
project by following this official guide and this tutorial. I'm following the exact steps that are mentioned but I'm getting this error that Property 'get' does not exist on type 'Cache'.
Here's the exact code
import {User} from './user.entity'
import {Resolver, Query, ResolveField, Args, Parent, Mutation} from '@nestjs/graphql'
import { UsersService } from './users.service';
import { PostsService } from '../posts/posts.service';
import { CurrentUser } from 'src/auth/auth.resolver';
import { CACHE_MANAGER, Inject, UseGuards } from '@nestjs/common';
import { GqlAuthGuard } from 'src/auth/graphql-auth.guard';
import { Cache } from 'cache-manager'; <---------this is you need to import
@Resolver(of => User)
export class UsersResolver {
constructor(
@Inject(CACHE_MANAGER) private cacheManager: Cache,
private usersService: UsersService,
private postsService: PostsService,
) {}
@Query()
async getUsers() {
const value = await this.cacheManager.get('key'); //Now .get property is working.
if(value){
console.log({
data: value,
loadsFrom: 'redis cache'
})
}
return await this.usersService.findAll();
}
}
import { Cache } from 'cache-manager';
– Pelmas