Nocache tag memory issue when otherwise not caching
Closed this issue · 1 comments
Bug description
If you use a nocache
tag while STATAMIC_STATIC_CACHING_STRATEGY=null
or while STATAMIC_STATIC_CACHING_STRATEGY=half
and you are on an excluded page (according to config('statamic.static_caching.excluded.urls')
), your nocache session will add an entry with every page load.
I've pinpointed the issue to here: https://github.com/statamic/cms/blob/4.x/src/StaticCaching/NoCache/StringRegion.php#L16
It seems that str_random
is used to allow the nocache
tag to work within loops. In testing, if I remove the random string append, it only broke the Tests\StaticCaching\HalfMeasureStaticCachingTest::it_can_keep_parts_dynamic_using_nocache_tags_in_loops
test.
With the random string append, when you are not caching the content it generates a new key for the nocache placeholder every single time and adds it to the session. Eventually, your session file becomes huge and you'll start getting out of memory exceptions.
You can circumvent this behavior by wrapping the nocache
tag in a cache
tag, thereby caching the key that is generated, but it doesn't work for nocache
tags within loops.
It seems like this may be related to #7039
I'm working on a PR, but I wanted to report it here first in case the team was already aware and there was a fix on the way.
How to reproduce
I've provided as minimal a reproduction as I could here with instructions on setting it up:
https://github.com/joetannenbaum/statamic-nocache-bug
This is a fresh Laravel app with a fresh installation of Statamic inside of it with two routes, a simple Antlers layout file, and two simple Antlers page templates.
Logs
No response
Environment
Environment
Application Name: Laravel
Laravel Version: 10.26.2
PHP Version: 8.2.10
Composer Version: 2.6.4
Environment: local
Debug Mode: ENABLED
URL: localhost
Maintenance Mode: OFF
Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: NOT CACHED
Drivers
Broadcasting: log
Cache: statamic
Database: mysql
Logs: stack / single
Mail: smtp
Queue: sync
Session: file
Statamic
Addons: 0
Antlers: runtime
Stache Watcher: Enabled
Static Caching: half
Version: 4.24.0 Solo
Installation
Existing Laravel app
Antlers Parser
runtime (new)
Additional details
No response
Thank you for the details.
Duplicate of #7039 though. A fix is not currently on the way. A PR would be greatly appreciated. 🤗