[1.x] perf: add MemoryCacheSettingsRepository layer to eliminate per-call Redis fetches#20
Merged
Merged
Conversation
RedisCacheSettingsRepository::get() calls all() on every invocation, which calls cache->remember() on every call — a Redis GET each time. With ~60–100 settings reads per page request, each returning the 154 KB flarum:settings blob, this alone accounts for the majority of Redis egress bandwidth. Wrapping with MemoryCacheSettingsRepository restores the per-request in-process cache that Flarum core's SettingsServiceProvider provides by default. After the first settings read per request, all subsequent reads within the same request are local array lookups with zero network cost. Redis is hit at most once per request instead of once per settings->get() call. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
RedisCacheSettingsRepository::get()callsall()on every invocation, which callscache->remember()every time — a RedisGETof the fullflarum:settingsblob on each call.On a typical forum page, settings are read 60–100 times (core serializers, frontend JS variable injection, middleware, extensions). Each call fetches the entire settings blob from Redis — on production this is ~154 KB. That's up to ~15 MB of Redis egress per page load from settings reads alone, which at scale accounts for the majority of observed Redis outbound bandwidth (~300 Mbps).
Flarum core's
SettingsServiceProviderusesMemoryCacheSettingsRepositoryto provide a per-request in-process cache — one load, then array lookups.fof/redis'sSettingsprovider replaces the entire binding without restoring this layer.Fix
Wrap
RedisCacheSettingsRepositorywithMemoryCacheSettingsRepository, restoring the three-layer chain:After this change, Redis is hit at most once per request for settings instead of once per
settings->get()call.Impact
Expected Redis egress reduction: ~95%+ of settings-related bandwidth eliminated. On production (Nothing Community), this should bring Redis outbound bandwidth from ~300 Mbps down to ~5–15 Mbps.
No behaviour change — invalidation on
ClearingCache,Enabled,Disabledevents is unchanged. The memory cache is request-scoped (PHP-FPM worker lifetime), so settings changes propagate on the next request after Redis invalidation.