Welcome to the Treehouse Community
Looking to learn something new?
Carlos Carmona17,354 Points
How to use Cache within Wordpress plugin?
I'm developing a plugin that uses a lot of Querys and this makes the site go slow.
One of the solutions I found is to implement Cache to my Querys, but I see that there are 2 kinds:
Non-Persistent Cache and Transient type. So now I'm confuse on witch one to use. Is there any course here that could guide me with this?! Or anyone can guide me on this one?!
Sue Dough35,800 Points
First try to optimize your queries. Maybe share some code here.
This really depends. If its just normal post queries I would just use the caching functions. Where I may use transisents would be this example:
I have 200,000 posts. I want to find out 4 times a day which 10 fit in the algorithim I wrote. I need to run an expensive query to grab 10 post ids that will take 5-15 seconds and just returns 10 post ids. These 10 posts ids are just 65 characters in length when put all together. This may make sense to put in a transient for X amount of time. I would then set these in a variable and use that with the post__in paramater.
What you SHOULD NOT DO is store a bunch of HTML static content for the query in a transient. Simply store the post ID's to then use in a query if its very expensive.
Try them both out and test the performance.