page-cache
page-cache copied to clipboard
File Write Failure Due to Long URL Slugs in Page Cache
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’sput()method.
- The
Illuminate/Filesystem/Filesystem.php:204- The underlying
file_put_contents()call fails due to the long file name.
- The underlying
Steps to Reproduce:
- Enable the Silber page cache middleware in a Laravel application.
- Access a URL with a slug longer than 255 characters.
- 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