Set-PSUCache allows for multiple values with the same key, is this intended?
1. Violates the core principle of key-value stores
The cache is fundamentally a key-value store, and each key should be unique. Allowing multiple values for the same key breaks this model and can cause confusion, inconsistency, and unexpected behavior.
2. Unpredictable behavior
When multiple values exist for the same key:
Which one is returned when you call Get-Cache?
Are values returned in order of insertion, time, or priority?
What happens if you update the cache — does it overwrite one, all, or none?
This ambiguity leads to bugs that are hard to trace and debug.
3. Data inconsistency and logic errors
Inconsistent cache values for the same key can cause business logic failures, especially in multi-user dashboards or background jobs that depend on accurate, current state information.
4. Makes the cache harder to manage and debug
Imagine trying to troubleshoot a value mismatch and realizing there are several values stored for the same key. This creates unnecessary complexity for developers and support teams.
5. Performance and memory overhead
Caching is meant to improve performance, but storing multiple values under the same key increases memory usage and defeats the efficiency gains you’d expect from a cache.
6. Undermines concurrency safety
PowerShell Universal apps often run in multi-threaded or concurrent environments (dashboards, APIs, scheduled jobs). If multiple values can exist under a single key, race conditions and data corruption become more likely.
7. Misleads developers
Developers expect Set-Cache -Key "MyKey" -Value "abc" to replace the previous value. If instead it silently adds another value for the same key, that’s counter-intuitive and leads to incorrect assumptions in code.
Did you avoid setting same Key with -persist on and off on purpose :D? Because this is exactly the problem. And when I want to remove one it always defaults to the oldest one