Custom controller page performance #6913
-
I have a few routes set up to use custom controllers in my Statamic 3.3 site hosted on Forge. I've noticed that performance for the pages that are using custom controllers is very slow, almost like those pages are not using any caching. I have a very simple controller set up that just grabs and entry and returns a view that dumps the entry to the screen. This page takes up to 10 seconds to load while the same entry when viewed through the default Statamic routes loads in just a few hundred ms. Any ideas what may be going on? |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 3 replies
-
Can you show the code? |
Beta Was this translation helpful? Give feedback.
-
Here's one controller that is showing the performance issue:
Here's the template:
The content partial looks like this:
|
Beta Was this translation helpful? Give feedback.
-
I should also mention I'm using the 'half' caching strategy. I double checked that the URLs to the slow pages are not in the exclude array. I turned on debugbar and noticed that the pages with custom controllers don't appear to be cached - debugbar shows views and messages only for those slower pages. If I turn off half caching all of the pages perform similarly slow and debugbar shows messages and views for all pages on the site. Is there a trick to getting Statamic static caching working with custom controllers? |
Beta Was this translation helpful? Give feedback.
-
You've mentioned you're using static caching. If you disable static caching and load one of the regular Statamic routes, is it just as slow as your custom route? |
Beta Was this translation helpful? Give feedback.
-
If I disable static caching, all pages load equally slow. If I enable it, only the custom controller routes load slow.
It definitely appears that static caching doesn’t work for custom controller routes, but I’m not sure if that’s by design.
We recently upgraded the Forge server to PHP 8.1 from 7.4 which may also be a clue.
Scott Metoyer
***@***.***
…On Oct 19, 2022 at 6:59 AM -0700, Jason Varga ***@***.***>, wrote:
> the same entry when viewed through the default Statamic routes loads in just a few hundred ms.
You've mentioned you're using static caching.
If you disable static caching and load one of the regular Statamic routes, is it just as slow as your custom route?
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Clearly there's an issue regarding the load times, but in order to enable static caching on your custom route, you should get it to use the cache middleware. Route::get('...')->middleware([
Statamic\StaticCaching\Middleware\Cache::class
]); |
Beta Was this translation helpful? Give feedback.
Clearly there's an issue regarding the load times, but in order to enable static caching on your custom route, you should get it to use the cache middleware.