Skip to content

Does include IdentityCache automatically cache the model its included in? #390

Open

Description

@johnernaut

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 of Foo's attributes?
  • Is there a way to prevent Foo from being cached (since I only want it's association to be cached)?

Activity

  1. dylanahsmith commented on Oct 17, 2019

    @dylanahsmith
    Contributor

    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 #211. Are you using memcached_store as recommended in the README?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions