Skip to main content

Definition

Assembly: Microsoft.OData.Mcp.Core.dll Namespace: Microsoft.OData.Mcp.Core.Configuration Inheritance: System.Object

Syntax

Microsoft.OData.Mcp.Core.Configuration.DistributedCacheConfiguration

Summary

Configuration for distributed caching.

Remarks

Distributed cache configuration specifies how the MCP server connects to and uses distributed caching services like Redis or SQL Server for sharing cache data across multiple instances.

Constructors

.ctor

Initializes a new instance of the DistributedCacheConfiguration class.

Syntax

public DistributedCacheConfiguration()

.ctor Inherited

Inherited from object

Syntax

public Object()

Properties

ConnectionString

Gets or sets the connection string for the distributed cache.

Syntax

public string ConnectionString { get; set; }

Property Value

Type: string? The connection string used to connect to the distributed cache service.

Examples

For Redis: “localhost:6379” For SQL Server: “Server=(localdb)\mssqllocaldb;Database=DistCache;Trusted_Connection=true;“

Remarks

The format of the connection string depends on the cache provider type. For Redis, this would be a Redis connection string. For SQL Server, this would be a SQL Server connection string.

DefaultAbsoluteExpiration

Gets or sets the default absolute expiration for distributed cache entries.

Syntax

public System.Nullable<System.TimeSpan> DefaultAbsoluteExpiration { get; set; }

Property Value

Type: System.Nullable<System.TimeSpan?>? The maximum time span that cache entries remain valid regardless of access.

Remarks

Absolute expiration ensures that entries are removed from the cache after a fixed period, regardless of how frequently they are accessed. This is useful for ensuring data freshness.

DefaultSlidingExpiration

Gets or sets the default sliding expiration for distributed cache entries.

Syntax

public System.Nullable<System.TimeSpan> DefaultSlidingExpiration { get; set; }

Property Value

Type: System.Nullable<System.TimeSpan?>? The time span that cache entries remain valid after their last access.

Remarks

Sliding expiration resets the expiration time each time an entry is accessed, keeping frequently used items in the cache longer. If not specified, entries will use absolute expiration only.

InstanceName

Gets or sets the instance name for the distributed cache.

Syntax

public string InstanceName { get; set; }

Property Value

Type: string? A unique name identifying this cache instance.

Remarks

The instance name is used to create unique cache keys and separate cache data between different applications or environments sharing the same distributed cache infrastructure.

Methods

Clone

Creates a copy of this configuration.

Syntax

public Microsoft.OData.Mcp.Core.Configuration.DistributedCacheConfiguration Clone()

Returns

Type: Microsoft.OData.Mcp.Core.Configuration.DistributedCacheConfiguration A new instance with the same settings.

Equals Inherited Virtual

Inherited from object

Syntax

public virtual bool Equals(object obj)

Parameters

NameTypeDescription
objobject?-

Returns

Type: bool

Equals Inherited

Inherited from object

Syntax

public static bool Equals(object objA, object objB)

Parameters

NameTypeDescription
objAobject?-
objBobject?-

Returns

Type: bool

ForRedis

Creates a configuration for Redis distributed caching.

Syntax

public static Microsoft.OData.Mcp.Core.Configuration.DistributedCacheConfiguration ForRedis(string connectionString, string instanceName)

Parameters

NameTypeDescription
connectionStringstringThe Redis connection string.
instanceNamestringThe cache instance name.

Returns

Type: Microsoft.OData.Mcp.Core.Configuration.DistributedCacheConfiguration A distributed cache configuration for Redis.

ForSqlServer

Creates a configuration for SQL Server distributed caching.

Syntax

public static Microsoft.OData.Mcp.Core.Configuration.DistributedCacheConfiguration ForSqlServer(string connectionString, string instanceName)

Parameters

NameTypeDescription
connectionStringstringThe SQL Server connection string.
instanceNamestringThe cache instance name.

Returns

Type: Microsoft.OData.Mcp.Core.Configuration.DistributedCacheConfiguration A distributed cache configuration for SQL Server.

GetHashCode Inherited Virtual

Inherited from object

Syntax

public virtual int GetHashCode()

Returns

Type: int

GetType Inherited

Inherited from object

Syntax

public System.Type GetType()

Returns

Type: System.Type

MemberwiseClone Inherited

Inherited from object

Syntax

protected internal object MemberwiseClone()

Returns

Type: object

MergeWith

Merges another configuration into this one, with the other configuration taking precedence.

Syntax

public void MergeWith(Microsoft.OData.Mcp.Core.Configuration.DistributedCacheConfiguration other)

Parameters

NameTypeDescription
otherMicrosoft.OData.Mcp.Core.Configuration.DistributedCacheConfigurationThe configuration to merge into this one.

Remarks

Only non-null and non-empty values from the other configuration will override values in this configuration. This allows for partial updates without losing existing settings.

ReferenceEquals Inherited

Inherited from object

Syntax

public static bool ReferenceEquals(object objA, object objB)

Parameters

NameTypeDescription
objAobject?-
objBobject?-

Returns

Type: bool

ToString Inherited Virtual

Inherited from object

Syntax

public virtual string ToString()

Returns

Type: string?

Validate

Validates the distributed cache configuration.

Syntax

public System.Collections.Generic.IEnumerable<string> Validate()

Returns

Type: System.Collections.Generic.IEnumerable<string> A collection of validation errors, or empty if the configuration is valid.