Skip to content

- Optimize settings retrieval with runtime and per-class config caching.#132

Closed
djabdou50 wants to merge 2 commits intoglorand:masterfrom
custplace:dev
Closed

- Optimize settings retrieval with runtime and per-class config caching.#132
djabdou50 wants to merge 2 commits intoglorand:masterfrom
custplace:dev

Conversation

@djabdou50
Copy link
Copy Markdown

Optimize Settings Performance with Enhanced Caching Strategy

Overview

This PR implements significant performance optimizations for the HasSettingsTable trait by introducing a multi-layered caching strategy that reduces Redis calls and improves runtime efficiency.

✨ Key Changes

Performance Improvements

  • Runtime Caching: Added per-instance runtime cache ($settingsRuntimeCache) that eliminates redundant Redis calls within the same request
  • Config Caching: Implemented static configuration caching to avoid repeated config() calls across instances
  • Optimized Query: Enhanced __getSettingsValue() to use select() for targeted column retrieval and support eager loading to prevent N+1 queries

New Features

  • Cache Management: Added clearSettingsCache() method to handle both runtime and Redis cache clearing

Developer Experience

  • Redis Monitoring: Updated README with helpful Redis request counting instructions for monitoring cache performance

Performance Impact

  • ZERO Redis calls after first settings access within a request (runtime cache)
  • Single Redis call per request when cache is enabled (previously could be multiple)
  • Reduced config lookups through static caching
  • Better database query efficiency with selective column loading

Technical Details

  • Maintains backward compatibility with existing API
  • Preserves existing configuration-based caching behavior
  • Supports eager loading for better query optimization
  • Thread-safe static config caching implementation

- Add `clearSettingsCache` method to handle clearing runtime and Redis cache.
- Update README with Redis request counting instructions.
@glorand
Copy link
Copy Markdown
Owner

glorand commented Oct 6, 2025

@djabdou50 Seems like the pipeline is red :(

- Add `clearSettingsCache` method to handle clearing runtime and Redis cache.
- Update README with Redis request counting instructions.
@glorand
Copy link
Copy Markdown
Owner

glorand commented Oct 16, 2025

🎉 Thank you for this excellent contribution!
Hi @djabdou50

First, I want to express my appreciation for the time and effort you've put into this PR. The performance optimizations you've identified—particularly the runtime caching, config optimization, and N+1 query prevention—are exactly the kind of improvements this package needs.

🚀 Exciting News: Major Refactor Coming
I'm happy to share that we're planning a massive refactoring, optimization, and modernization effort for the next major version (v9.0). This will include:
Architecture Changes

  • Single HasSettings trait with driver-based storage selection (replacing the current multiple-trait approach)
  • Unified driver system that will make caching strategies like yours much more maintainable
  • Built-in performance optimizations at the driver level

📋 Next Steps
Because of this upcoming architectural change, I'm going to close this PR rather than merge it. However, I want to emphasize:

  1. Your work is not wasted - The concepts and optimizations you've identified will be incorporated into the v9.0 design
  2. Your contribution matters - You've helped validate the performance pain points we need to solve
  3. We'd love your continued input - If you're interested, we'd welcome your feedback on the refactor design and testing of beta releases

@glorand glorand closed this Oct 16, 2025
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