Reputation: 654
I am using Memcached to store some PHP objects- lets say my object is a can of soda. Right now my memcached key for Pepsi is 4. So when I get 'soda_4' I get the Pepsi object.
The problem is that sometimes I know I need Pepsi, but I don't have the ID for it. So I need to make a DB call to get the ID before I can get the memcached object. This seems inefficient.
What would be perfect is if I could reference the same object by 2 keys (every time I save the object I have both the ID and Name).
At this point I'm considering saving 2 copies each time.
Any suggestions?
Upvotes: 1
Views: 475
Reputation: 47331
Method A:-
So, you can have reference to key B when you have object name.
The drawback is you have to make two calls.
Method B
You have already mentioned, create two cache using name and id as key.
The drawback is you are duplicating the data.
So, the capacity of memcache will reduce 50%.
I would prefer your suggestion, however
Upvotes: 2