Query caching

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
user___
Forum Contributor
Posts: 297
Joined: Tue Dec 05, 2006 3:05 pm

Query caching

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
mikeq
Forum Regular
Posts: 512
Joined: Fri May 03, 2002 3:33 am
Location: Edinburgh, Scotland

Post 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"
user___
Forum Contributor
Posts: 297
Joined: Tue Dec 05, 2006 3:05 pm

Reply

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post 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.
user___
Forum Contributor
Posts: 297
Joined: Tue Dec 05, 2006 3:05 pm

Reply

Post by user___ »

Thank you
Post Reply