CacheUpdate is not working properly
See original GitHub issueHi again @joshuaslate 😃
I was trying to use @CacheUpdate decorator from version 6.2.0 but for some behaviours I couldnt.
When I use @CacheUpdate on update operation, normally I have the my entity and possibility to set cacheKey by id, example:
@CacheUpdate({
cacheKey: ([{ id }]: any[]) => id,
cacheKeysToClear: 'todos',
})
async updateTodo(todo: Todo, dataToUpdate: TodoUpdateInput): Promise<Todo> {
const todoToUpdate = Object.assign(todo, dataToUpdate);
const updatedTodo = await this.todoRepository.save(todoToUpdate);
return updatedTodo;
}
Everything here works like a charm. But in my create operation I dont have id available immediatelly, example:
@CacheUpdate({
cacheKey: (data: any[]) => {
return 'invalid-id';
},
cacheKeysToClear: 'todos',
})
async createTodo(task: string): Promise<Todo> {
const todoAsEntity = await this.todoRepository.create({ task });
const todo = await this.todoRepository.save(todoAsEntity);
return todo;
}
When I try to create cacheKey data contains the task name instead of the result.
Any suggestions to fix it?
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (4 by maintainers)
Top Results From Across the Web
WordPress Changes Not Showing? Here's How to Fix ... - Kinsta
Having issues with WordPress changes not showing on your site? It's usually problems with caching - we'll show you how to fix the...
Read more >How Do I Fix My Caching Problems Or Clear Web Browser's ...
Try holding down the Shift key while pressing the Refresh button. Close your browser and re-open it (make sure you are NOT on...
Read more >How to Fix WordPress Website Not Updating Right Away
Step 1. Force Browser to Reload or Clear Cache. Sometimes your browser (specially Google Chrome) will show you a cached copy of your...
Read more >WordPress Changes Not Showing? 3 Methods to Fix It Right ...
When WordPress is not showing changes right away, it is most likely still displaying a cached version. Learn three ways to fix this...
Read more >How to Invalidate (or Update) Cache Correctly? - Wenbo Zong
Cache invalidation/update is often done incorrectly without noticing it. Let's take a look at the various strategies to update/invalidate cache. To start off, ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Huge Thanks @joshuaslate 😄
@joshuaslate some people recommend using Object.assign because my Entities sometimes has lifecycle methods, etc.