Repository navigation
refactor(@angular/build): prevent key collisions in cache namespaces - #34061
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a new NamespacedCacheStore class to handle key namespacing using length-prefix framing, which prevents key collisions. It refactors the Cache class to delegate namespacing to this wrapper and updates both LmdbCacheStore and SqliteCacheStore to use it. The feedback suggests decoupling NamespacedCacheStore from the specific value type of the underlying store by using CacheStore<any>, and explicitly specifying the type argument <V> when instantiating Cache and NamespacedCacheStore in the cache stores to ensure strict type safety.
7f90071 to
d6c0591
Compare
Previously, Cache formatted keys by joining the namespace and key with a single colon delimiter (${namespace}:${key}). This allowed potential key collisions if a namespace contained colons (such as 'a' with key 'b:c' versus 'a:b' with key 'c').
While this was not an issue in existing usages because all current namespaces are fixed, colon-free identifiers and keys are hash digests, it presented an architectural risk as caching usages expand.
Namespacing is now encapsulated in a dedicated NamespacedCacheStore wrapper that frames keys using length-prefix encoding (<length>:<namespace>:<key>). The length prefix eliminates delimiter ambiguity regardless of what characters appear in the namespace or key. Additionally, Cache has been decoupled from namespace management, simplifying MemoryCache and internal request tracking.
d6c0591 to
d8150f1
Compare
|
This PR was merged into the repository. The changes were merged into the following branches:
|
|
This pull request has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Previously, Cache formatted keys by joining the namespace and key with a single colon delimiter (${namespace}:${key}). This allowed potential key collisions if a namespace contained colons (such as 'a' with key 'b:c' versus 'a:b' with key 'c').
While this was not an issue in existing usages because all current namespaces are fixed, colon-free identifiers and keys are hash digests, it presented an architectural risk as caching usages expand.
Namespacing is now encapsulated in a dedicated NamespacedCacheStore wrapper that frames keys using length-prefix encoding (
<length>:<namespace>:<key>). The length prefix eliminates delimiter ambiguity regardless of what characters appear in the namespace or key. Additionally, Cache has been decoupled from namespace management, simplifying MemoryCache and internal request tracking.