Skip to content

V14: Cache user by id#16139

Merged
bergmania merged 7 commits intov14/devfrom
v14/feature/cache-user-by-id
Apr 25, 2024
Merged

V14: Cache user by id#16139
bergmania merged 7 commits intov14/devfrom
v14/feature/cache-user-by-id

Conversation

@Zeegaan
Copy link
Copy Markdown
Member

@Zeegaan Zeegaan commented Apr 24, 2024

Notes

  • We need to cache user by id aswell, because all content have creatorId (as int) and thus when we index content, user by id gets called for each content item, therefore we need to cache the user to avoid a lot of db calls.

How to test

  • Put a breakpoint in the UserRepository.Get(int id) method
  • Assert that first time a user gets retrieved, the GetCacheItem should return null (not in the cache
  • Assert that the second time the user gets retrieved GetCacheItem should now have a user.
  • Update the users name (or something else, name is easiest)
  • Get the user again, and assert that the GetCacheItem returns null (Updated user should NOT be in the cache)
  • Get the user once last time, and assert that it is indeed cached again, with the updated name

Comment thread src/Umbraco.Core/Cache/Refreshers/Implement/UserCacheRefresher.cs Outdated
Comment on lines +22 to +27
public record JsonPayload
{
public int Id { get; init; }

#region Refresher
public Guid Key { get; init; }
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This creates a lot of bulk, can also be a class.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the general pattern used for these JsonPayloads, see ContentCacheRefresher & MemberCacheRefresher 😁

And IMO records are the correct type here (also the plan to change the others) as this is used purely to pass data 😊

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The compiler creates a lot of unnecessary code for records, these simple types are better suited for a regular class.

@bergmania bergmania merged commit 7bd4995 into v14/dev Apr 25, 2024
@bergmania bergmania deleted the v14/feature/cache-user-by-id branch April 25, 2024 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants