Shopify / Shopify/identity_cache

An option to skip should_use_cache? method

Open
#521 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
2k
Forks
174
Avg merge
13m
Merged PRs (30d)
3

Description

I've just found that if a query is wrapped inside a transaction, IdentityCache will call the database directly

https://github.com/Shopify/identity_cache/blob/8fcaa32633bb3406c01adc32147a0e0c85aff56b/lib/identity_cache.rb#L151

However, in my case, there are some models doesn't need this (read a lot and rarely write)

Is there an option to skip this feature? Eg:

class TestModel < ApplicationRecord
  include IdentityCache
  skip_transaction: true
end

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in lib/identity_cache.rb around line 151, where should_use_cache? is referenced, and trace how transaction handling is applied to included models. Define how a per-model skip_transaction option should affect that behavior, then verify the requested TestModel configuration works without bypassing normal caching elsewhere.

Written by the indexing model from the issue text.

Assessment

Tech stack
rails, ruby
Domain
backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.