samedi 18 juillet 2015

RoR Memcache Delete/Replace entry

I have a Ruby on Rails 3 application. I have a user input a url, have delayed_jobs scrape the url in the background with nokogiri, set a cache value with the returned image filenames and then I get that cached value and proceed. This is happening before a [Recommendation] object is created so I don't have the id yet.

When a user enters a url and gets images back, those are stored in a memcached key (called "image_files"). My problem is if they decide to change the url and run another scrape on the same uncreated yet object. The cache value remains the same - it doesn't pick up the new values. I've tried the various cache methods I can think of: delete the key, insert a nil value, insert an empty value, etc. but none work. If I could append the recommendation.id as part of the cache key that would work but as it doesn't exist yet, I can't.

So how do I do this? Replace the cache key with the new values.

Aucun commentaire:

Enregistrer un commentaire