Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Caching Mechanism #695

Closed
KerryRitter opened this issue May 16, 2018 · 13 comments
Closed

Caching Mechanism #695

KerryRitter opened this issue May 16, 2018 · 13 comments

Comments

@KerryRitter
Copy link

I'm submitting a...


[ ] Regression 
[ ] Bug report
[X] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

What is the motivation / use case for changing the behavior?

Supporting a simple in-memory cache provider out of the box would be a great, useful feature. Probably as an external installable package, i.e. @nest/cache. See https://docs.microsoft.com/en-us/aspnet/core/performance/caching/memory?view=aspnetcore-2.0 for an example.

@KerryRitter
Copy link
Author

KerryRitter commented May 16, 2018

https://www.npmjs.com/package/node-cache would probably be an ideal package to support "under the hood" of the Nest provider.

I'd be happy to write this provider if you think it's a good idea, @kamilmysliwiec.

@kamilmysliwiec
Copy link
Member

Yeah, go for it! Maybe, let's create an interceptor that we could even put in the @nestjs/common as a built-in interceptor. CacheInterceptor sounds quite good :)

@kamilmysliwiec
Copy link
Member

Hi @KerryRitter, any updates here? 🔥

@KerryRitter
Copy link
Author

I haven't been able to do much lately but this is on my to-do! Anyone is free to take over, happy to help where I can

@zuohuadong
Copy link
Contributor

+1

@frozenex
Copy link

+1

@kamilmysliwiec
Copy link
Member

CacheModule just landed in 5.3.0. Read more here https://docs.nestjs.com/techniques/caching

@xmlking
Copy link

xmlking commented Aug 31, 2018

it wold be nice to have Method level @Cache annotation as well for service methods

@Injectable()
export class ProductService {
 @Cache(myStore, { ttl: 60 })
    public async getProducts(): Promise<string[]> {
        // return seed data from database
        return [...];
    }
}

@danil-z
Copy link

danil-z commented Sep 26, 2018

Is there a way to expose some generic cache (CacheStore) to have get and set methods to cache any arbitrary data?!

@kyle-mccarthy
Copy link

@danil-z I was able to do this by injecting the cache manager into my cache service, you can checkout an example at https://github.com/kyle-mccarthy/nest-next-starter/blob/master/src/cache/cache.service.ts

@mohammadrafigh
Copy link

@danil-z this issue has been closed, it would be great to make another issue for this request.

@ruscon
Copy link

ruscon commented May 22, 2019

@kamilmysliwiec how to invalidate cache ?

common use case

  1. api method getUser -> cache
  2. api method updateUser -> invalidate cache

only manually ?

@lock
Copy link

lock bot commented Sep 23, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Sep 23, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

9 participants