Cody,
That has happened to me before but I honestly didn't look into it too closely at the time. I assumed it had to do with marshalling and methods named id. My workaround was just to set id to something else prior to inserting into the cache and then setting it back when I got it out of the cache, e.g.
obj._id =
obj.id #obj is an OpenStruct so this just brings _id into existence
cache.write('key',obj)
obj = cache.read('key')
obj.id = obj._id
Obviously that's seriously inelegant so your email reminded me to look into this more closely. It turns out that it is related to the marshalling but not in the way I thought. The OpenStruct subclass, TwitterStruct, returned by Grackle methods defines an attr_accessor :id so that an attribute named id can be successfully set and retrieved on the OpenStruct. If I hadn't done that, the id on the TwitterStruct gets set but the getter always returns the object's internal id (since id is defined on all Objects). However, it introduces a problem because OpenStruct actually interjects itself into the marshaling process and the id attr_accessor means that the id attribute actually gets bypassed during dumping and loading as defined on OpenStruct.
So anyway, here's a monkey patch to fix this annoyance. I'll get this into an official release in the near future:
class TwitterStruct < OpenStruct
def id
_id
end
def id=(val)
self._id = val
end
end
It looks weird but it ensures that the _id attribute gets set on the OpenStruct so that the value for id gets marshaled and unmarshaled correctly.
Hayes