StringCache class

StringCache provides an append-only cache of strings that can be used to reuse the same string object instance when a string is being dynamically created at runtime (e.g., loaded from an XML file or database).

public sealed class StringCache

Public Members

name description
StringCache() Constructs a new instance of the StringCache class.
GetOrAdd(…) Gets an existing string from the cache, or adds it if it’s not currently in the cache.

Remarks

Using this class is similar to calling string.Intern except that all strings cached by StringCache can be collected when this instance is GCed; interned strings never get freed.

To free the strings held by this string cache, release all references to this object, and to other objects that hold the strings in the cache.

See Also