Skip to content

refactor(router): remove CachingRouter - #41733

Merged
DeepDiver1975 merged 1 commit into
masterfrom
refactor/remove-caching-router
Jul 28, 2026
Merged

refactor(router): remove CachingRouter#41733
DeepDiver1975 merged 1 commit into
masterfrom
refactor/remove-caching-router

Conversation

@DeepDiver1975

Copy link
Copy Markdown
Contributor

Description

Removes OC\Route\CachingRouter. It caches generated URLs in the distributed memory cache, and it is slower than not caching at all: measured at 9.1% slower than plain OC\Route\Router for parameterless routes, and within a few percent either way for routes with parameters. A cache whose lookup costs more than the work it avoids is a net loss, and this one also put per-instance URL strings into a network-reachable backend.

Only four references existed: the class, its single instantiation in Server.php, and two git-ignored generated classmaps. Server.php now always returns new \OC\Route\Router($c->getLogger()).

This removes the only in-tree caller of ICacheFactory::isAvailable(). The interface method is kept — it is @since 7.0.0 public API.

Drive-by: apps/files/appinfo/routes.php:67 was the one place naming the concrete router in a docblock (@var $this \OC\Route\Router); it now says \OCP\Route\IRouter, matching every other routes file.

Reviewer notes

  • Behaviour genuinely changes inside the test suite: under PHPUNIT_RUN all three cache tiers are ArrayCache (Server.php:482-488), so isAvailable() is true and the caching router was live in CI. That is why the full suite was run rather than just tests/lib/Route.
  • If your local classmap is stale you may need composer dump-autoload.

Related Issue

  • Fixes n/a — found while auditing distributed-cache usage for GHSA-488r-cjpq-p3vc

Motivation and Context

Deletes a cache that costs more than it saves and needlessly widens the distributed-cache surface.

How Has This Been Tested?

  • test environment: PHP 8.3.32, sqlite.
  • test case 1: benchmark A/B of CachingRouter vs Router — 9.1% slower without parameters, ±few % with. This is the reason for the change.
  • test case 2: new testRouterIsNotCached() in tests/lib/Route/RouterTest.php asserts the class no longer exists and that the service is a plain Router. tests/lib/ServerTest.php:233 still asserts instanceof IRouter and passes.
  • test case 3: full tests/lib — 7149 tests, 40221 assertions, no new failures. Run in full precisely because the caching router was live under PHPUnit, so URL memoisation really does change.
  • test case 4: make test-php-style and phan clean.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Database schema changes (next release will require increase of minor version instead of patch)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Technical debt
  • Tests only (no source changes)

Checklist:

  • Code changes
  • Unit tests added
  • Acceptance tests added
  • Documentation ticket raised: n/a
  • Changelog item, see TEMPLATE

🤖 Generated with Claude Code

@DeepDiver1975
DeepDiver1975 requested a review from a team as a code owner July 27, 2026 14:19
CachingRouter stored every generated url in the distributed memory cache for an
hour. Benchmarking it against the plain Router showed the cache to be a net
loss - roughly 9% slower for parameterless routes, since generating a url is
cheaper than a cache round trip - while giving urls a second place to live where
they can go stale or be tampered with.

The Router service is now always a plain OC\Route\Router.
ICacheFactory::isAvailable() loses its only in-tree caller but stays, as it is
public API.

While here: apps/files/appinfo/routes.php was the only routes file annotating
$this with the concrete router instead of the IRouter interface.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Signed-off-by: Thomas Müller <1005065+DeepDiver1975@users.noreply.github.com>
@DeepDiver1975
DeepDiver1975 force-pushed the refactor/remove-caching-router branch from 1916507 to c76ba0f Compare July 27, 2026 14:32
@DeepDiver1975 DeepDiver1975 self-assigned this Jul 27, 2026
@DeepDiver1975 DeepDiver1975 added this to the development milestone Jul 27, 2026
@DeepDiver1975
DeepDiver1975 requested a review from phil-davis July 27, 2026 14:34
@DeepDiver1975
DeepDiver1975 merged commit 3443c3e into master Jul 28, 2026
29 checks passed
@DeepDiver1975
DeepDiver1975 deleted the refactor/remove-caching-router branch July 28, 2026 09:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

2 participants