The whole point of caching is to avoid actual database reads, but with your
idea you will end up doing a lot of unnecessary database reads and in
extreme cases you might end up doing more reads your way than if you didn't
have any caching at all.

The way to do it is to have a data access layer so that every time you want
to load a piece of data, you first check the cache, if it's not in the
cache you load it from the db and put it in the cache, and then your return
your object. That way you will do the minimal amount of database loads
necessary.

I don't know anything about PHP, there might already be cache-enabled ORMs
that does this for you.


/Henrik

On Fri, Feb 3, 2012 at 13:32, Robert Hanson <[email protected]> wrote:

> Hi,
>
> I have a plan to do this scenario using PHP and Memcached on my Social
> Networking project, please correct me if I'm wrong :
>
> just like any other social networking site out there, mostly users just
> 'read' database content, instead of 'writing' it. right?
>
> so, I have a plan to 'read' EVERYTHING from the database once the user
> login (session created), such as : number of friends, birth date, today
> friend's post, etc then store it into Memcached server.
>
> unless the user logged out or click 'yesterday friend's post', user won't
> read the database again but read all the data from Memcached.
>
> maybe it will act like Gmail, user will see loading bar when they login
> into their account. but once they have it, everything runs faster.
>
> is this possible thing to do with Memcached?
>

Reply via email to