🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
SharedBigValue
This page was created by Hans.karlsen on 2023-04-09. Last edited by Wikiadmin on 2026-07-29.

You can use SharedBigValue to reduce memory use when one MDriven Turnkey or MDrivenServer process hosts multiple ecospaces that load the same large text or binary attribute value.

What SharedBigValue does

SharedBigValue is an in-process cache mechanism for large values that originate from persistent storage (PS). When multiple ecospaces load the same qualifying value, the cache can retain one shared representation instead of retaining a separate large value for each ecosystem load.

For example, assume 1,000 users view the same stored image or large text document through a single Turnkey process. If the value qualifies, SharedBigValue allows those loads to refer to one cached large value rather than holding 1,000 copies in process memory.

This mechanism applies when a process, such as MDriven Turnkey or the MDrivenServer service, holds several ecospaces at the same time.

When a value qualifies

A value is considered for SharedBigValue only when all of the following conditions are true:

  • The loaded attribute value is a byte[] or a string.
  • The value is larger than 8,192 bytes.
  • The value version is int.MaxValue.
  • The values have the same object ID and attribute ID.
  • The values have the same type-system checksum.
  • The value was loaded from persistent storage and reaches ApplyDataBlock.

Large binary attributes can, for example, be used for images; see Documentation:Attribute.Eco.BlobType.

How cache resolution works

The cache stores SharedBigValue entries in a static dictionary. The dictionary key consists of the cache and the SharedBigValue identity.

When a qualifying value is loaded from persistent storage:

  1. MDriven checks whether a SharedBigValue entry already exists for the cache key.
  2. If an entry exists, MDriven uses the existing SharedBigValue.
  3. If no entry exists, MDriven creates a SharedBigValue, stores it in the dictionary, and uses that entry.

Reads are protected by a read lock. The lock can be upgraded to a write lock when MDriven must create and store a new entry.

Public methods that retrieve a cache value check whether the cached value is a SharedBigValue. If it is, they resolve it to the actual string or byte[] value before returning it to the caller.

Scope and limitations

SharedBigValue is intended for already persisted, loaded values. It does not change the normal handling of newly written or updated large values.

Situation SharedBigValue behavior
A large text or binary value is loaded from persistent storage and meets all eligibility rules MDriven may reuse an existing SharedBigValue.
A large value is created, written, or updated MDriven handles it as before; it does not attempt to share the new or updated block through SharedBigValue.
A new model is uploaded and the type-system checksum changes Existing SharedBigValue entries are not actively removed. The expected operational response is that existing ecospaces are recreated.

The type-system checksum prevents values from different model versions from being treated as the same shared value. Model uploads that require ecosystem recreation are considered an uncommon production scenario.

Test SharedBigValue

Test with content that is larger than 8,192 bytes. Use both a large text value and a binary value, such as an image, when your model contains both.

  1. Create or identify a model object with a large text attribute and/or a large binary attribute.
  2. Run the model in MDriven Turnkey.
  3. Open the application as two different users, or use two separate browser sessions.
  4. In one session, load the object containing the large value.
  5. In the other session, load the same object so that both ecospaces access the same persisted value.
  6. Update the large text or image in one session.
  7. Verify that the changed value is shown in the other session after it is refreshed or reloaded.

This test verifies normal update behavior while multiple users access the same large object. SharedBigValue targets memory reuse for database-loaded values; it does not make updated blocks shareable during the write/update path.

Performance considerations

The expected benefit is lower process memory consumption when many ecospaces load the same large strings or byte arrays.

The mechanism adds checks and cache lookup work for large string and byte[] values. It avoids that work for values at or below the threshold and for values that do not meet the remaining eligibility requirements.

Configuration

SharedBigValue is enabled by default. To prevent values from qualifying, set the threshold to int.MaxValue:

FetchedBlockHandler.kBigValueThreshold = int.MaxValue;

With this setting, no practical string or byte[] value reaches the SharedBigValue threshold.

See also