<p>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.</p>
<p>If you're worried about licensing, I believe you can upgrade from 2 -&gt; 3 without buying a new license and then from 3 -&gt; 4. You just need to be up to date on the license subscription (cheaper than a brand new license).</p>
<p>Craft 2 is officially End of Life.</p>

CC BY-SA 4.0
2023-09-21T17:06:56.643Z
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
CC BY-SA 4.0
2023-09-22T18:15:32.240Z
You should definitely upgrade to Craft 3 first, following the guide: https://craftcms.com/docs/3.x/upgrade.html and once you're comfortable that everything is working, then upgrade to Craft 4: https://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
CC BY-SA 4.0
2023-09-21T01:08:13.180Z
2023-09-21T01:08:13.180Z
cherrykoda
<p>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.</p>
<p>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.</p>
<p>That avenue would require a custom module (PHP) and creating a database migration.</p>

CC BY-SA 4.0
2023-09-21T17:10:31.787Z
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
CC BY-SA 4.0
2023-09-22T18:18:34.193Z
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
CC BY-SA 4.0
2023-09-21T01:12:46.670Z
2023-09-21T01:12:46.670Z
cherrykoda
<p>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.</p>
<pre><code>{%cache%}
{{craft.aipagconnpart.AiPagConnPartVariable(name_var) }}
{%endcache%}
</code></pre>
<p>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?</p>

<plugin-development><cache><craft2><api><speed>
Craft 2 Caching RESTful API Results Displayed On Page
# Craft 2 Caching RESTful API Results Displayed On Page

(Asked by: username_0 on 2023-09-20)

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?

**Tags:** plugin-development, cache, craft2, api, speed


---

## 2 answers

### Answer by username_1 on 2023-09-21. Score: 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.

> **Comments:**
> **username_0**: 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  
> **username_1**: You should definitely upgrade to Craft 3 first, following the guide: https://craftcms.com/docs/3.x/upgrade.html and once you're comfortable that everything is working, then upgrade to Craft 4: https://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.  

---

### Answer by username_1 on 2023-09-21. Score: 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.

> **Comments:**
> **username_0**: 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  
> **username_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.  

---

