page-cache icon indicating copy to clipboard operation
page-cache copied to clipboard

File Write Failure Due to Long URL Slugs in Page Cache

Open isaac-bowen opened this issue 10 months ago • 0 comments

Issue: File Write Failure Due to Long URL Slugs in Page Cache

Description:
When caching pages with very long URL slugs, the generated cache file name exceeds the filesystem's maximum length (typically 255 characters), causing a "File name too long" error. This results in a 5xx error in Laravel.

Error Trace:

  • silber/page-cache/src/Cache.php:158
    • The put() method calls the Filesystem’s put() method.
  • Illuminate/Filesystem/Filesystem.php:204
    • The underlying file_put_contents() call fails due to the long file name.

Steps to Reproduce:

  1. Enable the Silber page cache middleware in a Laravel application.
  2. Access a URL with a slug longer than 255 characters.
  3. Observe the "File name too long" error in the logs.

Expected Behavior:
The caching mechanism should handle long URL slugs gracefully, for example by truncating or hashing the slug, to ensure the file name stays within the allowed limit.

Proposed Solution:

  • Modify the caching strategy to use a hashed or truncated file name.
  • Alternatively, add configuration options for customizing the file naming strategy.

Environment:

  • Laravel Version: 11.x
  • PHP Version: 8.3
  • Operating System: MacOS M4

isaac-bowen avatar Feb 14 '25 19:02 isaac-bowen