Best method to cache objects in PHP?

Posted by Martin Bean on Stack Overflow See other posts from Stack Overflow or by Martin Bean
Published on 2010-05-28T18:32:05Z Indexed on 2010/05/28 18:52 UTC
Read the original article Hit count: 117

Filed under:
|
|
|

Hi,

I'm currently developing a large site that handles user registrations. A social networking website for argument's sake. However, I've noticed a lag in page loads and deciphered that it is the creation of objects on pages that's slowing things down.

For example, I have a Member object, that when instantiated with an ID passed as a construct parameter, it queries the database for that members' row in the members database table. Not bad, but this is created each time a page is loaded; and called more than once when say, calling an array of that particular members' friends, as a new Member object is created for each friend.

So on a single page I can have upwards of seven of the same object, but containing different properties.

What I'm wanting to do is to find a way to reduce the database load, and to allow persist objects between page loads. For example, the logged in user's object to be created on login (which I can do) but then stored somewhere for retrieval so I don't have to keep re-creating the object between page loads.

What is the best solution for this? I've had a look at Memcache, but with it being a third-party module I can't have the web host install it on this occasion. What are my alternatives, and/or best practices in my case?

Thanks in advance.

© Stack Overflow or respective owner

Related posts about php

Related posts about class