Closed vibro closed 5 years ago
Could you debug this issue and try to also include the prefix_options and the persisted into the json?
I think I was able to solve it by adding persisted:
def cache_write(key, object)
if object.is_a? Enumerable
json = object.map { |o| { object: o.to_json, persistence: o.persited? } }.to_json
else
json = { object: object.to_json, persistence: object.persited? }.to_json
end
result = cached_resource.cache.write(key, json, :race_condition_ttl => cached_resource.race_condition_ttl, :expires_in => cached_resource.generate_ttl)
result && cached_resource.logger.info("#{CachedResource::Configuration::LOGGER_PREFIX} WRITE #{key}")
result
end
def json_to_object(json)
if json.is_a? Array
json.map { |attrs| self.new(attrs[:object], attrs[:persistence]) }
else
self.new(json[:object], json[:persistence])
end
end
If this is the right direction, happy to open a PR for it.
Did the instantiation of the object work?
That all looks like it is the right direction. Feel free to create a pull request.
@Daniel-ltw 💪for being on top of this. I'll make a new release with https://github.com/mhgbrown/cached_resource/pull/43 soon.
published in 5.1.1 https://rubygems.org/gems/cached_resource/versions/5.1.1
@mhgbrown @vibro did all the work. Kudos to @vibro
Absolutely. I just mean you acting as a "face" of cached_resource.
Happy to help out a fellow developer as and when I can.
Thanks everyone!
I recently updated to 5.1.0 after experiencing the problems that #40 fixed. However, I tried updating an object I had retrieved from the cache, and the persistence field is missing. This means instead of calling update, ActiveResource called create on the object.
I tried calling find with reload => true, but it looks like it writes to the cache and then reads from there, causing the same problem.
Old Behavior (5.0.1):
New behavior:
Is there a way to keep persistence? Or stop reading directly from the cache in instances where I want to update?