Skip to content

Simplify cache by removing namespaces - #967

Open
giuscris wants to merge 3 commits into
2.xfrom
refactor/simplify-cache
Open

giuscris wants to merge 3 commits into
2.xfrom
refactor/simplify-cache

Conversation

@giuscris

Copy link
Copy Markdown
Member

This pull request refactors the cache subsystem to simplify cache management, improve extensibility, and align with PSR standards. The main changes include removing the concept of cache namespaces in favor of named caches, and refactoring the CLI commands to support arbitrary named caches. Additionally, configuration and UI schemas are updated to reflect these changes.

Cache subsystem refactor:

  • Removed cache namespaces and NamespacedCacheInterface, replacing them with named caches managed by CacheManager. [1] [2] [3] [4] [5] [6]
  • Refactored CacheManager to manage caches by name, enforce name validation, and support adding, retrieving, and listing named caches.

CLI and command improvements:

  • Updated CacheCommand to operate on arbitrary named caches, removed special handling for "pages" cache, and generalized cache clearing and stats reporting. [1] [2] [3] [4] [5] [6]
  • Updated UpdatesCommand to use the new cache manager.

Configuration and UI schema updates:

  • Changed system.yaml config and schema to remove global cache settings, moving "pages" cache settings under cache.pages with new enabled, path, and ttl options. [1] [2] [3] [4] [5]
  • Updated services configuration to define cache.pages as a named cache instance from the cache manager.

Code cleanup:

  • Removed obsolete namespace validation logic and related exceptions. [1] [2] [3]

@giuscris giuscris added this to the 2.4.0 milestone Oct 21, 2026
@giuscris giuscris self-assigned this Oct 21, 2026
@giuscris
giuscris requested a lite review from Copilot October 26, 2026 22:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved critical configuration migration and unsafe cache-path issues, plus a moderate cache-path overlap issue, block approval.

2 open issues
What changed in this PR

This pull request replaces cache namespaces with named caches managed by CacheManager, updating cache consumers, configuration, commands, controllers, and tests accordingly.

Changes:

  • Refactors cache implementations and management APIs around validated named caches.
  • Updates cache loading, clearing, statistics, update handling, and page caching.
  • Migrates configuration schemas and removes obsolete namespace-specific APIs.
  • Adds compatibility handling for deprecated cache configuration.
File Description
tests/​Unit/​Services/​Loaders/​ConfigServiceLoaderTest.php Tests deprecated cache configuration migration and cache-file loading.
tests/​Unit/​Services/​Loaders/​CacheServiceLoaderTest.php Tests named cache construction, validation, handlers, TTLs, and paths.
tests/​Unit/​Controllers/​PageControllerTest.php Updates page-cache tests for named cache configuration and TTL compatibility.
tests/​Unit/​Cache/​FilesCacheTest.php Updates file-cache tests for direct paths instead of namespaces.
tests/​Unit/​Cache/​CacheTestCase.php Removes namespace-specific shared cache tests and updates cache factory signatures.
tests/​Unit/​Cache/​CacheManagerTest.php Tests named cache registration, validation, lookup, and reserved names.
tests/​Unit/​Cache/​ArrayCacheTest.php Updates array-cache construction tests.
formwork/​src/​Services/​Loaders/​ConfigServiceLoader.php Loads cached configuration and rewrites deprecated cache options.
formwork/​src/​Services/​Loaders/​CacheServiceLoader.php Builds and registers configured named caches.
formwork/​src/​Panel/​Controllers/​UpdatesController.php Clears all managed caches after updates.
formwork/​src/​Panel/​Controllers/​CacheController.php Supports clearing named caches from the panel.
formwork/​src/​Controllers/​PageController.php Uses the pages cache configuration and supports the new page TTL option.
formwork/​src/​Commands/​UpdatesCommand.php Clears all managed caches after CLI updates.
formwork/​src/​Commands/​CacheCommand.php Generalizes cache clearing and statistics to named caches.
formwork/​src/​Cache/​NamespacedCacheInterface.php Removes the obsolete namespaced cache interface.
formwork/​src/​Cache/​FilesCache.php Removes namespace handling and uses the configured path directly.
formwork/​src/​Cache/​Exceptions/​InvalidNamespaceException.php Removes the obsolete namespace exception.
formwork/​src/​Cache/​CacheManager.php Adds named-cache registration, validation, lookup, and reserved-name handling.
formwork/​src/​Cache/​ArrayCache.php Removes namespace handling from in-memory caches.
formwork/​src/​Cache/​AbstractCache.php Switches cache implementations to PSR cache interfaces.
formwork/​schemes/​config/​system.yaml Updates the system configuration schema for the pages cache.
formwork/​config/​system.yaml Defines the pages cache as a named cache.
formwork/​config/​services/​services.php Registers CacheManager and exposes the pages cache service.

Review effort: Lite

Comment on lines +92 to +94
if (!is_string($path) || $path === '') {
throw new InvalidArgumentException(sprintf('Invalid "path" option for cache "%s": expected non-empty string, %s given', $name, get_debug_type($path)));
}
Comment on lines +115 to +117
foreach (['enabled' => 'enabled', 'path' => 'path', 'time' => 'ttl'] as $deprecated => $replacement) {
if (!isset($data['system']['cache']) || !is_array($data['system']['cache']) || !array_key_exists($deprecated, $data['system']['cache']) || is_array($data['system']['cache'][$deprecated])) {
continue;
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants