Search code examples
phpmemcachedimplementationcache-invalidation

Basic Memcached Implementation in PHP


I understand the concept on Memcache but i have a doubt.

Lets say:

I have a table 'users' with the three columns: userid username and password.

Lets say the query is $query="select * from users". For the first time, the query gets executed and gets stored in the memcache as md5($query)->result.

So when this query gets executed next time, the md5 hash of $query is executed. It matches and results are fetched from memcache.

BUT what if i have to just select 2 parameters from the above query.

like $query = select username,password from users.

What do i do then? I would ideally like to fetch it from the same key as select * from users since all the data needed for 'select username,password from users' is present in the result corresponding to the key for 'select * from users'.

How do i manage such an issue?


Solution

  • Memcache/PHP doesn't know your databases internal structure. You have to do this kind of optimalization manually, if you need this.

    Otherwise mysql's query cache probably fits better if this kind of intelligent caching is a requirement.