Page 1 of 1

Query caching

Posted: Tue Jan 30, 2007 8:10 am
by user___
Hi guys,
I have recently read about query caching. Thay say that by caching query results the iven Search engine will become incredibly fast. I know that MySQL uses caching function but I wonder whether it is a good practice to cache your queries despite this by using Php class. Any suggestions will be appreciated.

Posted: Tue Jan 30, 2007 8:22 am
by feyd
Unless you use a less volatile storage, PHP can and will only cache the results for the current request.

The general idea for cache the result data is simply storing it into an array. Nothing more, often.

Posted: Tue Jan 30, 2007 8:32 am
by mikeq
Well mysql cacheing happens behind the scenes and will be handled automatically and hopefully efficiently. I cant imagine a home grown solution would be any better.

Do you have a specific problem you are trying to overcome? I am a great believer in "if it aint broke, dont fix it"

Reply

Posted: Tue Jan 30, 2007 8:52 am
by user___
My idea was for example if there is a search engine and a user tries to search for "Apple" and in an hour another user tries to do the same search the results to have already been saved somewhere as simple XML or pure text and when there is a match with previous search instead of sending queries to the MySQL engine simply get the result from a file. I am not sure that it will benefit and that is way I am asking here.

Posted: Tue Jan 30, 2007 9:25 am
by feyd
I would suggest staying away from it for now. Caching is a very difficult subject when you get into the deeper segments that it spiders into. I think your time is better suited for other pursuits right now. No offense, I hope.

Posted: Tue Jan 30, 2007 9:34 am
by Maugrim_The_Reaper
Given it's searching a broad suggestion would be to cache. I'd implement the search functionality first and check it's speed before implementing caching - give you a baseline against which to measure any improvement.

MySQL has an internal query cache - but it relies on the database administrator enabling it and allowing it a sufficient memory limit. I've noticed it's disabled on quite a few shared hosts so depends on what your hosting environment is (can you edit MySQL settings and restart the server?).

Again, it's better to have something working before you consider whether or not caching is required. Especially for a database.

Reply

Posted: Tue Jan 30, 2007 9:43 am
by user___
Thank you