Is there a way to "cache" query results?
Hi to all!
I would like to put a sidebar to my site, which will contain some database driven things (top forum posts, top downloads, latest additions and so on) However since my host is not very fast, i guess this will make page loading too slow. My question is:
1)Is there any way of putting that info in "cache" (or anything similar?) so that the database will be queried only on the first page view, and then on the second, third etc by the same visitor the data will be recalled from cache rather than regenerated from scratch?
2)Alternatively, is there a way to , say, make the query to the database automatically once every 1 (or 3 or 6) hours and then the results be stored in a text file (or html) automatically updated which i could include via ssi or iframe?
Waiting for your views on the subject!
Suzanne posted this at 00:54 — 12th June 2003.
She has: 5,507 posts
Joined: Feb 2000
Java Beans will do this for you. Or you can manually do the more common searches yourself (setting them up, I mean) and use a php script to update them as needed.
So, yes.
For the php script, you would create a cronjob to run the script at whatever intervals you chose.
zollet posted this at 05:17 — 12th June 2003.
He has: 1,016 posts
Joined: May 2002
As Suzanne mentioned, you could create a cron job that would basically run a PHP script that would build HTML pages based on the common searches. Then your script would check to see if the user does a common search and redirect them to a HTML page, if not then query the database.
...OR...
...you could simply move to a new and better web host
Cheers.
Mark Hensler posted this at 09:23 — 12th June 2003.
He has: 4,048 posts
Joined: Aug 2000
I don't think he needs this for a search engine. Sounds more like forum hacks.
I would probably keep the latest info in a seperate file which you could include where desired. As for getting information into the file...
I don't like option 1. Doesn't feel right. Requires session management, etc. etc. Just too much messy.
Cron. Good idea. Not the best. It will query when it doen't need to, and won't update the content as soon as changes are made.
My suggestion is to hack the files which are use to post topics, threads, articles, and whatever else you want to track. Basically, when the script adds another article (or whatever) to the database, you append (or prepend) it to your static include file, and remove the oldest one. This is more work for you, but it wont query when not necessary and will update as soon as new content is posted.
Mark Hensler
If there is no answer on Google, then there is no question.
mairving posted this at 12:27 — 12th June 2003.
They have: 2,256 posts
Joined: Feb 2001
I have seen it done on phpbuilder's site, I believe. Their's is probably a forum hack.
nicora posted this at 15:21 — 12th June 2003.
He has: 267 posts
Joined: Nov 2001
What Server-side langauge are you using? php, asp, cfm ?
k8oylos posted this at 18:21 — 12th June 2003.
They have: 16 posts
Joined: Mar 2003
Hey hey hey i am totally lost.
First of all i use php, but i am just an amateur and quite new to it.
Now i have no idea what Java Beans is, and i would prefer to leave it aside if there is no other solution.
moving to a better host? yes i am thinking of it indeed, but as i said, i am just an amateur doing it for fun, so no income-->not much money on server bills!
The other two now.
Cronjob. Another new word for me, but if what i understood is right it could do the job well. i want basically queries like top and latest forum posts, latest downloads and articles and it wouldn't really matter if it didn't update on the spot.
Where can i find more on cronjob (tutorial or whatever)?
And finally
Basically, when the script adds another article (or whatever) to the database, you append (or prepend) it to your static include file, and remove the oldest one. This is more work for you, but it wont query when not necessary and will update as soon as new content is posted.
Didn't quite get this. And where is it on phpbuilder.com?
And since i mentioned phpbuilder, i saw an article at them regarding putting php content in html page via javascript. Does this have any effect on speed?
k8oylos posted this at 18:36 — 12th June 2003.
They have: 16 posts
Joined: Mar 2003
I just took a look on google on cron job, and it said it needs shell access to run one. Does this mean that i need shell access on my server?
mairving posted this at 19:56 — 12th June 2003.
They have: 2,256 posts
Joined: Feb 2001
Some of the site managers like Cpanel have a cron job function. Otherwise, you would have to have shell access via telnet or SSH.
Mark Irving
I have a mind like a steel trap; it is rusty and illegal in 47 states
ROB posted this at 06:46 — 13th June 2003.
They have: 447 posts
Joined: Oct 1999
mysql to 4.0 caches common queries in memory, simply upgrading should solve your problems.
if you can't upgrade, you can cache the data in a single table and retrieve it with a single query. just make sure you empty it out any time the data changes.
k8oylos posted this at 22:10 — 13th June 2003.
They have: 16 posts
Joined: Mar 2003
How do i cache the data in a table? Would i have to update if manually? Cos the whole question is about automating the whole thing. It would be impossible for exemple to handle manually the latest forum posts
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.