how to handle inconsistency?
I am having many issues when using .fetch method
IdentityCache::RecordNotFound: An error occurred on xxx
I could solve it by overriding the .fetch method with
module IdentityCache
module WithPrimaryIndex
module ClassMethods
def fetch(id, includes: nil)
fetch_by_id(id, includes: includes) || find(id)
end
end
end
end
which is not a correct way
I am just wondering do you have this issue too in Shopify?
@saiqulhaq-hh what kind of issues are you facing? I'm having issues with IDC as well, as described at https://github.com/Shopify/identity_cache/issues/525
@saiqulhaq-hh IDC will try to load the record from cache (if enabled) and if it's missing it will pull it from DB, so when IDC raises RecordNotFound error , it couldn't find it in DB either.
IDC will cache the absence of a record, so this could just be a cache inconsistency, which is an expected occurrence when cache invalidations fails. I think we failed to document this, so I opened #529 to update the caveats to mention this symptom of lost cache invalidations:
IdentityCache also caches the absence of database values (e.g. to avoid performance problems when it is destroyed), so lost cache invalidations can also result in that value continuing to remain absent. As such, avoid sending the id of an uncommitted database record to another process (e.g. queuing it to a background job), since that could result in an attempt to read the record by its id before it has been created. A cache invalidation will still be attempted when the record is created, but that could be lost.
Also, we would ideally have a way to opt-out of nil caching (as discussed in #501)
thanks @dylanahsmith the readme doc looks good