question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CacheUpdate is not working properly

See original GitHub issue

Hi 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:closed
  • Created 3 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
lucasmonstrocommented, Aug 1, 2020

Huge Thanks @joshuaslate 😄

1reaction
lucasmonstrocommented, Jul 28, 2020

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found