Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft CacheKey value is always fetched in Live reading mode #62

Closed
chrispenny opened this issue Nov 28, 2022 · 0 comments · Fixed by #65
Closed

Draft CacheKey value is always fetched in Live reading mode #62

chrispenny opened this issue Nov 28, 2022 · 0 comments · Fixed by #65
Labels
bug Something isn't working

Comments

@chrispenny
Copy link
Member

chrispenny commented Nov 28, 2022

Problem statement

To be clear, this is still safe, as every <% cached %> wrapper also includes the current reading mode by default. The issue is that we're currently not using separate keys for ?stage=Stage and ?stage=Live. Effectively, we invalidate our keys every time a draft change is made.

Why is this happening?

CacheKey::findOrCreate()

When we attempt to find an existing CacheKey we force the ORM into the DRAFT reading mode. This is important, because if we're in a LIVE reading mode, and there is an existing CacheKey that hasn't yet been published, then we still want to find that "draft only" record. If we don't, we'd end up creating a new CacheKey instead of simply publishing the one that already exists.

The issue though, is that we then return this cache key, which was fetched in DRAFT, and so it will always return whatever the DRAFT value is.

Solution

I think we could first add a "find only" query to see if a CacheKey exists in the active stage. If one does exist, we can likely just return the CacheKey immediately. This would also mean that we can skip all of the "make sure the key is published" stuff that happens later in findCacheKeyHash(), and that would likely be a significant performance improvement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant