[wp-hackers] transients and caching on your own
halukkaramete at gmail.com
Sat Jan 25 18:23:34 UTC 2014
Say there is a URL such as http://www.domain.com/pageX.
Say that URL happens to be a magazine/news like URL and has a ton of cross
taxonomy queries and runs over 100 queries blah blah. The point is that the
page is very loaded.
And this page happens to attract a ton of traffic.
To top it off, there are a few more URLs like that throughout the site.
Total cache, super cache is not an option for me. Due to their complex
configs and weirdo behaviors, I confidently say, that they will never be
part of my wordpress work. Their too many features introduce more problems
than they solve. I'm done with them.
So, I am looking for a 80/20 solution that addresses my main need - by
building my own. With the right guidance, this should take less than a day.
I'm not looking for an elaborate solution, like those that have 100+
features, settings and more...
All I want is this:
have a piece of code like this ( the question I will be asking you later is
WHERE THIS CODE SHOULD GO ) and run it in the right hooks.
'url_1' => 'num_of_secs_to_cache|my_filter_function_name',
'http://www.domain.com/pageX' => '60*60|xyx_my_filter',
in this array, left side needs no explanation.
right side though has a separator (|) and I use that to visually split the
data (expire time and filter ).
The array is pretty visual and tells what's happening at a glance.
The plan is to store the URLs' corresponding HTMLs (all the way from
<!doctype html> to </html>) in a transient - where the transient ID is made
up on the fly from the URL associated with it. That I can do without a
What I'd like to get an insight from a master like you is that where this
piece of code should go?
I need an action hook as early as possible but after wordpress loaded the
transient API, & it knows about the current user login status.
I sense that location would be template_redirect. Am I right?
But on the other hand, at that time, wordpress would have already run the
main query which is no use to me, because I already got the HTML in a
transient (which includes the results of that main query too) So, there is
a waste in there...
So, Is it the "pre_get_posts" hook that I should go after... See my issue?
Once we plug the code in the right place, the "handle_my_cache();" function
to take over and do its thing.
which is mainly,
* check if the current user is logged in, and if so,
exit out and let WordPress run its course.
* check if the transient is alive and if so,
load it and prevent from WordPress taking its further course.
* and if the transient is not alive, let WordPress run its course,
but at the end, let the transient be created for the next time around.
Could you guide me which hook(s) do I need here?Thank you for your time
More information about the wp-hackers