Question

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?

Was it helpful?

Solution 2

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.

OTHER TIPS

Maybe you should store the "users" results under a key that doesn't changed based on what criteria you're selecting. You've already stored your entire user table into the key md5("select * from users"). So you can just:

  1. Get the stored result from Memcache
  2. This will return you what you originally stored, i.e. the entire user table, which includes the username and password.
  3. Then use this result and only use the subset of data that you need.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top