Skip to content

Conversation

@petruki
Copy link
Member

@petruki petruki commented Sep 1, 2025

This pull request significantly enhances the cache system to support automatic cache invalidation when domains are deleted and improves the cache-worker communication protocol. It also expands the test suite to verify cache updates for domain creation and deletion scenarios. The changes ensure the cache stays in sync with the database, not just for updates but also for removals, and refactor the worker logic for clarity and extensibility.

Cache invalidation and update improvements:

  • Added support for cache deletions: when a domain is removed from the database, the cache is now notified and deletes the corresponding entry (src/helpers/cache/index.js, src/helpers/cache/worker-manager.js, src/helpers/cache/worker.js). [1] [2] [3] [4] [5]
  • Implemented a protocol for the worker to request and receive the list of cached domain IDs, enabling detection of deletions (src/helpers/cache/worker-manager.js, src/helpers/cache/worker.js). [1] [2] [3] [4] [5]

Refactoring and code quality:

  • Refactored worker logic: renamed checkForUpdates to refreshCache, split out logic for checking deletions and updates, and improved error handling and documentation (src/helpers/cache/worker.js). [1] [2] [3] [4]

Test suite enhancements:

  • Added tests to verify that the cache is updated when a new domain is created and that cache entries are removed when a domain is deleted (tests/unit-test/cache.test.js).
  • Improved the domain update waiting helper to be more robust and general (tests/unit-test/cache.test.js).

Minor improvements:

  • Simplified code by removing unused lastUpdate fields from cache entries, focusing on version numbers for cache validation (src/helpers/cache/index.js, src/helpers/cache/worker.js). [1] [2] [3]
  • Used optional chaining and improved null checks for worker shutdown (src/helpers/cache/index.js).

@petruki petruki added this to the v1.1.0 milestone Sep 1, 2025
@petruki petruki self-assigned this Sep 1, 2025
@sonarqubecloud
Copy link

sonarqubecloud bot commented Sep 1, 2025

@petruki petruki merged commit 846954d into master Sep 1, 2025
5 checks passed
@petruki petruki deleted the staging branch September 1, 2025 07:13
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