class CouchRest::Database alias :old_save_doc :save_doc alias :old_delete_doc :delete_doc attr_writer :rcache # Automatically add the created_at and updated_at time fields to the # document and also save it back to redis with a ttl. def save_doc doc, bulk = false, batch = false doc['created_at'] ||= Time.now doc['updated_at'] = Time.now res = old_save_doc doc, bulk, batch rcache.set doc['_id'], doc return res end # Purge the key from redis after a successful delete def delete_doc doc res = old_delete_doc doc rcache.del doc['_id'] return res end # Fetch from redis first and if not, go to CouchDB. def cache_get id rcache.get id do self.get id rescue nil end end end