Skip to content

Support a serializable classes value on caches#58911

Merged
taylorotwell merged 1 commit into
12.xfrom
unserialize
Feb 18, 2026
Merged

Support a serializable classes value on caches#58911
taylorotwell merged 1 commit into
12.xfrom
unserialize

Conversation

@taylorotwell

Copy link
Copy Markdown
Member

No description provided.

@taylorotwell taylorotwell merged commit bd6972d into 12.x Feb 18, 2026
73 checks passed
@taylorotwell taylorotwell deleted the unserialize branch February 18, 2026 22:34
waldemar-p added a commit to waldemar-p/statamic-font-awesome that referenced this pull request Apr 7, 2026
Laravel v12.53.0 (Feb 2026) introduced a serializable_classes config
for cache stores (laravel/framework#58911) that restricts which PHP
classes can be deserialized. When active, unserialize() rejects any
class not on an explicit allowlist, turning it into
__PHP_Incomplete_Class.

Statamic v6.5.0 added Laravel 13 support, and upgrading Statamic also
pulled in Laravel 12.53+ where this feature became available. The
first manifestation of this issue appeared around Statamic v6.8.0:
the addon stored Icons, Icon, Kit, and Collection objects via
Cache::rememberForever(), which uses PHP serialize(). After the
Laravel update, these classes were not on the serialization allowlist
and became __PHP_Incomplete_Class upon retrieval.

Statamic v6.10.0 (statamic/cms#14416) explicitly added Statamic's own
classes to the allowlist, but third-party addon classes are not
included. This made the error persistent rather than intermittent.

Additionally, Statamic's GraphQL DefaultCache serializes the entire
JsonResponse object via Cache::put(). Objects nested in the Response
that are not on the allowlist also produce __PHP_Incomplete_Class,
breaking GraphQL response caching entirely. On top of this,
serializing the large icon collection (thousands of objects) caused
memory exhaustion on sites with standard PHP memory limits.

Changes:

- Replace Cache::rememberForever() with JSON file caching for icons,
  kit data, and styles. Cache files are stored in
  storage/framework/cache/font-awesome/ as plain JSON — no PHP
  serialization involved.

- Use streaming writes (fwrite per icon) for the icon cache to reduce
  peak memory usage when writing large icon collections.

- Add a separate styles cache so styles() no longer loads the full
  icon collection — just a small JSON array of style names.

- Serve cached icons JSON directly from disk via response()->file()
  in the controller, avoiding object instantiation entirely.

- Add instance-level $cachedIcons property to prevent redundant file
  reads within a single request.

- Introduce SafeResponseCache implementing Statamic's ResponseCache
  contract. Caches only the content string, status code, and headers
  array — all plain scalars — instead of the full Response object.
  Bound in ServiceProvider::boot() to override Statamic's DefaultCache
  which binds in register().
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant