Search code examples
memcachedinvalidationkey-value-store

memcached invalidation based on values


Is it possible to invalidate memcahced entries based on values.
In my app, I am assigning user in different groups and I store this mapping in memcached.

key = userID
value = groupID

So multiple userIds map to one groupID.

When I delete a particular group then I want to remove all entries in memcache store which have value as the groupID of the deleted group. So Essentially I want to delete the entries having particular values. How do I do it.


Solution

  • You cannot get key's by value in memcached. What you could do though is have a key called groupID that has a comma separated userID's. If you want to see who is part of a group then you could get the key called groupID and parse out the userID's. Then if you have a key for each userID you could delete them with the parsed userID's. You could use memcached's append function too to just append the userID's to a groupID key when a new user registers for you system.