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

fix: clear message goes to all bus instances + refactor: to optimize bus sync #39

Merged
merged 4 commits into from
Oct 9, 2024

Conversation

gkachru
Copy link
Contributor

@gkachru gkachru commented Oct 7, 2024

Since the channel name is the same, clear is called on all L1 instances of any cache stack with a sync bus. Clearing one namespace will clear the local caches on remote instances for ALL namespaces. Issues related to this are masked, since this only impacts the L1 cache and the L2 cache of other namespaces are still preserved.

However, since this will cause unnecessary processing of messages and clearing of L1 caches, I have added a namespace to the channel name of the bus to overcome this.

@gkachru
Copy link
Contributor Author

gkachru commented Oct 8, 2024

Also implemented a namespace cache in CacheStack to avoid unnecessary allocations. Recommend using emittery as the default event emitter to make bus message handling async.

@gkachru
Copy link
Contributor Author

gkachru commented Oct 9, 2024

Added a refactor of the bus related code, which is now optimised when namespaces are used:

  • Single bus per named cache (reduces Redis connections when large number of namespaces are used)
  • Support for sending namespaces on bus messages (including using binary encoding) and using it to access the appropriate local cache instance
  • Caching of namespaced stacks to reduce memory allocations
  • Added and modified existing test cases to cover more bus synchronization scenarios

All of the above is necessary if you use hundreds of namespaces and don't want to get hit by heavy memory usage and a high volume of bus messages that stall the main thread.

@gkachru gkachru changed the title fix: clear message goes to all bus instances fix: clear message goes to all bus instances + refactor: to optimize bus sync Oct 9, 2024
@Julien-R44
Copy link
Owner

Looks perfect to me. Many thanks for these quality PRs 👌

@Julien-R44 Julien-R44 merged commit 3813247 into Julien-R44:main Oct 9, 2024
4 checks passed
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.

2 participants