identity_cache
identity_cache copied to clipboard
Does `include IdentityCache` automatically cache the model its included in?
I have a model where I'm including IdentityCache
, let's call it Foo
. I don't necessarily want this model and all of its attributes cached, but I do want its relationship cached. I have a relationship defined like:
cache_belongs_to :thing
The cache works just fine for doing things like calling foo.fetch_thing
, but I noticed that when an attribute for the Foo
model is updated, I get logging that looks like:
[IdentityCache] expiring=Foo expiring_id=2342 ...
and then more output saying that a delete failed for IDC:7:blob:Foo:...
.
So I guess my questions are:
- By including the module, is
Foo
and its attributes being stored into cache whenever its called? - Any ideas why a
delete failed
would be consistently called when updating one ofFoo
's attributes? - Is there a way to prevent
Foo
from being cached (since I only want it's association to be cached)?
By including the module, is Foo and its attributes being stored into cache whenever its called?
It is a read-through cache, so it won't store Foo records in the cache if they aren't fetched through identity cache. However, include IdentityCache
does assume that it will be fetched, so it expires it to avoid stale reads if/when it is read from the cache. You can use include IdentityCache::WithoutPrimaryIndex
in Foo
to avoid these cache invalidations for this primary key index for Foo
.
Any ideas why a delete failed would be consistently called when updating one of Foo's attributes?
That sounds like it might be https://github.com/Shopify/identity_cache/issues/211. Are you using memcached_store
as recommended in the README?