fastapi-cache icon indicating copy to clipboard operation
fastapi-cache copied to clipboard

Implement `@cacheable, @cache_put, @cache_evict` like Spring cache.

Open mkdir700 opened this issue 2 years ago • 5 comments

This idea comes from Spring Cache, which mainly provides caching function for methods or functions, similar to functools.cache in Python.

These features are often applied to "CRUD" methods, while the target of fastapi-cache is HTTP interface functions. Therefore, I am not sure if these features can be implemented in fastapi-cache.

  • Cacheable

Annotation indicating that the result of invoking a method (or all methods in a class) can be cached.

https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/cache/annotation/Cacheable.html

  • CachePut

In contrast to the @Cacheable annotation, this annotation does not cause the advised method to be skipped. Rather, it always causes the method to be invoked and its result to be stored in the associated cache if the condition() and unless() expressions match accordingly.

https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/cache/annotation/CachePut.html

  • CacheEvict

Annotation indicating that a method (or all methods on a class) triggers a cache evict operation.

https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/cache/annotation/CacheEvict.html


If you have any further questions, please leave a message and I will reply as soon as possible.

mkdir700 avatar Nov 03 '22 13:11 mkdir700

What's the status of this issue, and could I request an english version?

mjpieters avatar May 15 '23 12:05 mjpieters

What's the status of this issue, and could I request an english version?

I'm very sorry, I have now updated this issue in English.

mkdir700 avatar May 16 '23 01:05 mkdir700

Thanks for updating, the summaries are really helpful!

I can kind-of see this work for FastAPI-Cache too, provided the arguments are compatible. It's something to think about for a post-v1.0.0 version.

mjpieters avatar May 17 '23 10:05 mjpieters

Yes, we can consider whether to implement it after version V1.0.0

mkdir700 avatar May 17 '23 10:05 mkdir700

is this feature added in newer release?

vithu30 avatar Jun 21 '23 05:06 vithu30