Most APIs in Optimizely CMS return read-only instances of objects, such as `
IContentLoader.Get<TContentData>` which return a read-only `
To make changes to read-only instances, create a writable clone with the `
CreateWritableClone` method, which has the following advantages:
**Reduce memory consumption** – Threads serving Web requests get the same instance of an object, which effectively reduces the amount of short-lived objects that are created.
**Improve performance** – Returning shared read-only instances offers better performance.
**Cleaner architecture** – This simplifies the implementation because you cannot make changes to an instance of an object shared with other threads.
Classes that have the read-only support implements the `
IReadOnly<T>` interface, which is defined as follows:
The lifecycle of a typical `
IContent` instance is as follows:
Create the `
IContent` instance as mutable (which means writeable).
Populate the `
IContent` instance with property values.
Call the `
IReadOnly.MakeReadOnly` method to ensure that any contained objects are made read-only. The object is immutable for the remainder of its lifetime.
Add the object to the cache.