Page 1 of 1

Cache function

Posted: Mon Jul 27, 2009 6:55 am
by dreamline
Hi All,
I'm thinking of writing a cache function for my website. I am thinking of doing a time based and/or sql based cache solution. My data changes about 20-30 times throughout the day, so I was wondering if it is wise to use caching or should I keep running the queries? Another question that I have is, if I decide to go for a caching function how would one deal with pages that also have pagination? That last one is bugging my mind on how to solve it. Especially when the pagination could contain up to 50 pages in total and I think that caching 50 pages is not wise, especially when data changes and you have to clear the cache and generate 50 new pages.

So my main question is: How would I solve the pagination issue? Maybe by caching the 5 first pages only?

Any ideas and tips are very much welcome.. :)

Thanks. )

Re: Cache function

Posted: Mon Jul 27, 2009 7:10 am
by Eran
Why are you caching? did you encounter performance problems that you cannot solve? for most regular sites, a well configured MySQL database is perfectly capable of serving anything very fast without caching (other than it's internal cache). Caching adds another layer of complexity that should be avoided if not needed.

Other than that, have a look at caching packages such as Zend_Cache

Re: Cache function

Posted: Mon Jul 27, 2009 7:47 am
by dreamline
Hi,
Well at the moment I do not see too many problems, the queries might slow the website a little down eventhough some queries are in my opinion quite heavy. But as time goes by and I'm improving functionality it might come in handy to have a cache function. The basic idea is good too grasp, however it's the small details like pagination that cause my mind to wonder.

Anyways I'll have a look into that Zend_cache and I also noticed that phpBB3 has a form of cache. So I will first dive into phpBB3 because it has pagination too and uses cache.

Thanks for the heads up! :)

Re: Cache function

Posted: Mon Jul 27, 2009 8:56 am
by jackpf
Yeah, I've read through some of phpBB's cache code, although I don't understand how they use it.

A forum is a very dynamic website, as in it's constantly changing, with new posts being added and removed, edited and so on...constantly.

How can they cache stuff that's constantly changing? I've never really understood that...

I suppose they could run a query to check if the data in the database is the same as the cache, but then they've already run the query, which goes against the point of having a cache...


But yeah, I agree with Pytrin...unless you have thousands of users online at the same time, or your content is updated at certain periods throughout the day, I don't think there's much point in having a cache. Although yeah, it'd be good to learn.