October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

Project the Response, Not the Cache: Avoiding Shared-DTO Mutation

A response filter can return the right translation while changing shared cached data. Separate authoritative DTOs from request-specific output, choose a safe projection strategy, and test what the next reader sees.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A response can be correct for the current request and still corrupt what a later reader sees. If an ASP.NET Core response filter translates values directly on a DTO that is also held in a shared cache, the next request may receive the first caller’s translated text instead of the authoritative source value. Keep cached data unchanged; build request-specific output that belongs to the response.

How a correct-looking response creates a later bug

Imagine a catalogue cache containing a product description in its source language. A request asks for another language, and a response filter replaces the DTO’s description with a translation. The first caller sees the expected output, so a test that checks only that response passes.

As an Amazon Associate I earn from qualifying purchases.

The problem is object ownership. If the response and cache refer to the same in-process DTO instance, assigning the translated string changes the cached object too. A later source-language request—or a background consumer reading the same object—can now see or persist presentation text as if it were source data. The response was right; the shared state was not.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Separate authoritative data, request context, and output

Keep three roles distinct:

  • Cached or domain data: the authoritative input, such as the source-language catalogue text.
  • Request context: the selector for presentation rules, such as the requested language.
  • HTTP response payload: request-specific output that can be transformed without changing shared or caller-owned objects.

This boundary is useful beyond localization: any per-request presentation change can create the same ownership bug when it is written back into an object shared with a cache or another consumer. The practical rule from Ivan Rossouw’s article is: “The practical rule is short: if a value is shared, treat it as immutable.”

Choose a response projection that fits the application

The right implementation depends on the application’s serializer contract and constraints. The invariant is more important than a particular API: request-specific work must not mutate cache-owned or caller-owned objects.

Map into a dedicated response model

Create a response-specific model from the authoritative DTO, applying presentation changes to the new model. This makes the ownership boundary visible in the types and keeps the cached representation intact. It does require maintaining a mapping and response model.

Clone before changing values

Copy the object or object graph, then apply transformations to the copy. Ensure the clone covers nested objects and collections; a shallow copy can leave nested mutable values shared with the cache.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Project while materializing the response

Substitute presentation values as the response is serialized or otherwise materialized, rather than assigning them to the source DTO. This can avoid maintaining a separate model, but it must work with the application’s actual result types and serializer configuration.

Keep the unchanged path cheap and define failure behavior

Projection has costs: JSON materialization, translation lookup work, and temporary allocations. If a request already uses the source representation, retain a pass-through path where appropriate. Measure transformed requests with representative payload sizes; the available comparison is qualitative and supplies no benchmark or performance percentage.

Decide which payloads are eligible before applying a response transformation. Error responses and security-sensitive payloads may need exclusion or different handling. Also decide what happens when projection fails. For a presentation feature, returning an untransformed response may be an acceptable fallback—or a feature failure. For redaction, an untransformed fallback can expose data that should not be visible, so the system may need to fail closed instead.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Test the next reader, not just the first response

A snapshot of the transformed response cannot establish that shared state stayed unchanged. Test the sequence that exposes the ownership bug:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. Put an object with source-language text into the same cache implementation the host uses.
  2. Request a transformed response and verify that the response contains the expected presentation value.
  3. Read the cached object again and verify that its source value has not changed.
  4. Request the source representation and verify that it still contains the original value.

Where practical, exercise this sequence through the real result filter and serializer configuration, not just a mapping helper. Add focused cases for nested collections, response wrappers, explicit JSON results, errors, exempt payloads, and projection failure. Those cases help reveal where a pipeline’s behavior differs from the ordinary DTO path.

What the source establishes

Ivan Rossouw’s “Project the Response, Not the Cache” was listed on DEV Community as posted October 1, 2026. The guidance describes an ownership invariant and qualitative implementation trade-offs; it does not report a measured performance comparison. The article’s indexed substantive text is the basis for this summary.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.