0

I have made a php plugin in Craft 2 which calls a RESTful API and displays the results on the template. The data is returned at about 8 seconds. I've surrounded the call to the plugin on the template page with cache/endcache tags, but that hasn't helped the slow performance caused by loading the data via html.

{%cache%}
{{craft.aipagconnpart.AiPagConnPartVariable(name_var) }}
{%endcache%}

Would there be more effective ways to use the Craft cache/endcache tags, or would this likely need some custom php coding to cache that RESTful data? Is caching like this effective when working with data returned from a plugin?

2 Answers 2

2

Honestly not trying to upsell you, but a ton of speed improvements have occured in Craft 3 and Craft 4 that would massively benefit overall performance here. I'd consider upgrading to at least Craft 3 to avoid code bottlenecks due to old Yii / PHP.

If you're worried about licensing, I believe you can upgrade from 2 -> 3 without buying a new license and then from 3 -> 4. You just need to be up to date on the license subscription (cheaper than a brand new license).

Craft 2 is officially End of Life.

2
  • Thanks! We're headed that way. We are in the process of changing web servers, and so the Craft upgrade will hopefully come soon thereafter. Would you recommend a good plan of action in doing the upgrades, for the smoothest transitions possible (accounting for deprecated code, etc)? Thanks
    – buck1112
    Commented Sep 21, 2023 at 17:06
  • 1
    You should definitely upgrade to Craft 3 first, following the guide: craftcms.com/docs/3.x/upgrade.html and once you're comfortable that everything is working, then upgrade to Craft 4: craftcms.com/docs/4.x/upgrade.html Going from 2 -> 3 could be intensive depending on your site (edits needed for modules/plugins). 3 -> 4 was pretty easy. If you run into any issues its probably been solved here on SE before.
    – cherrykoda
    Commented Sep 22, 2023 at 18:15
2

A non-upgrade option would be to evaluate your stored data, reduce as many external calls as you can. For connecting to an API you'll also want to evaluate whether the slowdown is occurring on your hosting or at the source... I've had APIs on ancient systems slow things down and been entirely outside of my control.

Sometimes a nice way to tackle this, if the API data doesnt need to be retrieved on-demand, is to make a custom table in Craft CMS and load the API data on a schedule to the local table. Use the table in your site calls, and update on a cron job to do a nightly sync of that data.

That avenue would require a custom module (PHP) and creating a database migration.

2
  • Would a new plugin for this purpose (creating a custom table/loading API data) be ideal? When you mentioned nightly sync, would that be a once daily update/sync? Thanks
    – buck1112
    Commented Sep 21, 2023 at 17:10
  • 1
    Once daily, nightly.... they are the same thing. Whatever schedule makes sense for your data. If you're dealing with slowness in retrieving the data you need, or if the data source going offline is a concern, then yes I do recommend storing the data locally on a schedule and referencing it there. As an example, I did this recently with a Book publisher that only allowed FTP connections for retrieving data (very slow). The job deals with thousands of books in one job at midnight each night.
    – cherrykoda
    Commented Sep 22, 2023 at 18:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.