You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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 existingCacheKey
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 newCacheKey
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 theCacheKey
immediately. This would also mean that we can skip all of the "make sure the key is published" stuff that happens later infindCacheKeyHash()
, and that would likely be a significant performance improvement.The text was updated successfully, but these errors were encountered: