From: Tony Garcia Date: 2008-02-15T07:33:34+09:00 Subject: Re: Memcached: Dealing with unknown keys Ben Bleything wrote: > On Fri, Feb 15, 2008, Tony Garcia wrote: >> I need to pass information (for example, an email address) based on user >> name from a rails application to a disconnected ruby process through the >> cache. The external process has no way to know what users are being >> passed to it. I had wanted to use the user name as the key, but it seems >> that I can't find the values of current keys in the cache - at least not >> with memcache-client. > > It sounds like you're trying to use the cache as a message queue, when > you should probably be using both in tandem... that is, store user data > in the cache, but send messages along the queue with the user name, so > the disconnected process can look it up in the cache. Only the username, email address, and a code are being stored - there are no messages or other items that need to be passed along. > Caching in general (and memcache in particular) are intended to speed up > slow data access, not to act as data repositories. Granted - and I am using memcache as a queue in this case. I've done a lot of looking and can't find much else that will do what I need - and Joyent has memcache already installed. If anyone has a better suggestion, I'd love to hear it. This is the best I've been able to figure out on my own. >> So far, about the best I've found is to set the cache as a hash: >> Cache["users"] = { "user1"=>"user1@example.com", >> "user2"=>"user2@example.com" } > > If you need to iterate over the usernames and the iterator has no way of > knowing what they are, that's your best bet. Not a great idea, though. I'm not too thrilled with using that method either, but as I said, it's the best I can come up with on my own. Any suggestions? -- Posted via http://www.ruby-forum.com/.