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.CachingConfiguration

Summary

Configuration for metadata and tool caching behavior.

Remarks

Caching configuration controls how long metadata and generated tools are cached to improve performance and reduce load on the underlying OData service. This class provides comprehensive caching options including provider selection, TTL settings, size limits, and advanced features like compression and warming.

Constructors

.ctor

Initializes a new instance of the CachingConfiguration class.

Syntax

public CachingConfiguration()

.ctor Inherited

Inherited from object

Syntax

public Object()

Properties

Compression

Gets or sets the compression configuration for cached data.

Syntax

public Microsoft.OData.Mcp.Core.Configuration.CacheCompressionConfiguration Compression { get; set; }

Property Value

Type: Microsoft.OData.Mcp.Core.Configuration.CacheCompressionConfiguration Configuration for compressing cached data to save memory/storage.

Remarks

Cache compression can significantly reduce memory usage for large cached objects at the cost of additional CPU overhead.

CustomProperties

Gets or sets custom caching properties.

Syntax

public System.Collections.Generic.Dictionary<string, object> CustomProperties { get; set; }

Property Value

Type: System.Collections.Generic.Dictionary<string, object> A dictionary of custom caching configuration values.

Remarks

Custom properties allow extending the configuration with cache provider-specific settings that don’t fit into the standard configuration properties.

DistributedCache

Gets or sets the distributed cache configuration.

Syntax

public Microsoft.OData.Mcp.Core.Configuration.DistributedCacheConfiguration DistributedCache { get; set; }

Property Value

Type: Microsoft.OData.Mcp.Core.Configuration.DistributedCacheConfiguration Configuration for distributed caching across multiple server instances.

Remarks

Distributed caching enables cache sharing between multiple MCP server instances for improved consistency and performance.

Enabled

Gets or sets a value indicating whether caching is enabled.

Syntax

public bool Enabled { get; set; }

Property Value

Type: bool true to enable caching; otherwise, false.

Remarks

When caching is disabled, metadata and tools will be regenerated for every request, which can impact performance but ensures the latest data is always used.

EnableStatistics

Gets or sets a value indicating whether to enable cache statistics collection.

Syntax

public bool EnableStatistics { get; set; }

Property Value

Type: bool true to collect cache statistics; otherwise, false.

Remarks

Cache statistics provide insights into cache hit rates, evictions, and performance metrics for monitoring and optimization.

EnableWarming

Gets or sets a value indicating whether to enable cache warming.

Syntax

public bool EnableWarming { get; set; }

Property Value

Type: bool true to pre-populate the cache on startup; otherwise, false.

Remarks

Cache warming pre-populates frequently accessed data to improve initial response times after server startup.

EvictionPolicy

Gets or sets the cache eviction policy.

Syntax

public Microsoft.OData.Mcp.Core.Configuration.CacheEvictionPolicy EvictionPolicy { get; set; }

Property Value

Type: Microsoft.OData.Mcp.Core.Configuration.CacheEvictionPolicy The policy used to determine which entries to evict when cache limits are reached.

Remarks

Different eviction policies optimize for different access patterns and performance characteristics.

KeyPrefix

Gets or sets the cache key prefix.

Syntax

public string KeyPrefix { get; set; }

Property Value

Type: string A prefix added to all cache keys to avoid collisions.

Remarks

Key prefixes are useful when multiple MCP server instances share the same cache infrastructure.

MaxEntries

Gets or sets the maximum number of cache entries.

Syntax

public System.Nullable<int> MaxEntries { get; set; }

Property Value

Type: System.Nullable<int> The maximum number of entries in the cache, or null for no limit.

Remarks

Entry count limits provide an alternative way to control cache size when individual entry sizes vary significantly.

MaxSizeMb

Gets or sets the maximum size of the cache in megabytes.

Syntax

public System.Nullable<int> MaxSizeMb { get; set; }

Property Value

Type: System.Nullable<int> The maximum cache size in MB, or null for no limit.

Remarks

Cache size limits prevent excessive memory usage. When the limit is reached, older entries will be evicted using the configured eviction policy.

MetadataTtl

Gets or sets the Time-To-Live (TTL) for metadata cache entries.

Syntax

public System.TimeSpan MetadataTtl { get; set; }

Property Value

Type: System.TimeSpan The duration to cache metadata before it expires.

Remarks

Metadata is typically stable and can be cached for longer periods. A shorter TTL ensures faster detection of schema changes.

ProviderType

Gets or sets the cache provider type.

Syntax

public Microsoft.OData.Mcp.Core.Configuration.CacheProviderType ProviderType { get; set; }

Property Value

Type: Microsoft.OData.Mcp.Core.Configuration.CacheProviderType The type of cache provider to use.

Remarks

Different cache providers offer different characteristics in terms of persistence, performance, and distributed caching capabilities.

QueryResultsTtl

Gets or sets the Time-To-Live (TTL) for query result cache entries.

Syntax

public System.TimeSpan QueryResultsTtl { get; set; }

Property Value

Type: System.TimeSpan The duration to cache query results before they expire.

Remarks

Query results represent actual data and should typically have shorter TTL values to ensure data freshness.

ToolsTtl

Gets or sets the Time-To-Live (TTL) for generated tools cache entries.

Syntax

public System.TimeSpan ToolsTtl { get; set; }

Property Value

Type: System.TimeSpan The duration to cache generated tools before they expire.

Remarks

Generated tools are derived from metadata and can be cached separately with different TTL values for performance optimization.

WarmingDelay

Gets or sets the cache warming delay after startup.

Syntax

public System.TimeSpan WarmingDelay { get; set; }

Property Value

Type: System.TimeSpan The delay before starting cache warming operations.

Remarks

A startup delay allows the server to fully initialize before beginning resource-intensive cache warming operations.

Methods

Clone

Creates a copy of this configuration.

Syntax

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

Returns

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

Disabled

Creates a configuration with caching disabled.

Syntax

public static Microsoft.OData.Mcp.Core.Configuration.CachingConfiguration Disabled()

Returns

Type: Microsoft.OData.Mcp.Core.Configuration.CachingConfiguration A caching configuration with all caching disabled.

Remarks

Disabled caching ensures the freshest data is always retrieved at the cost of performance. Useful for debugging or when data consistency is more important than performance.

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

ForDevelopment

Creates a configuration optimized for development environments.

Syntax

public static Microsoft.OData.Mcp.Core.Configuration.CachingConfiguration ForDevelopment()

Returns

Type: Microsoft.OData.Mcp.Core.Configuration.CachingConfiguration A caching configuration suitable for development.

Remarks

Development configurations use shorter TTLs and smaller cache sizes to ensure faster detection of changes during development cycles.

ForProduction

Creates a configuration optimized for production environments.

Syntax

public static Microsoft.OData.Mcp.Core.Configuration.CachingConfiguration ForProduction()

Returns

Type: Microsoft.OData.Mcp.Core.Configuration.CachingConfiguration A caching configuration suitable for production.

Remarks

Production configurations use longer TTLs, larger cache sizes, and enable advanced features like compression and warming for optimal performance.

GetHashCode Inherited Virtual

Inherited from object

Syntax

public virtual int GetHashCode()

Returns

Type: int

GetMetadataKey

Gets the cache key for a metadata entry.

Syntax

public string GetMetadataKey(string serviceUrl)

Parameters

NameTypeDescription
serviceUrlstringThe OData service URL.

Returns

Type: string The cache key for the metadata.

Exceptions

ExceptionDescription
ArgumentExceptionThrown when serviceUrl is null or whitespace.

GetQueryResultKey

Gets the cache key for a query result entry.

Syntax

public string GetQueryResultKey(string serviceUrl, string queryHash, string userContext = null)

Parameters

NameTypeDescription
serviceUrlstringThe OData service URL.
queryHashstringThe hash of the query parameters.
userContextstring?Optional user context for user-specific caching.

Returns

Type: string The cache key for the query result.

Exceptions

ExceptionDescription
ArgumentExceptionThrown when serviceUrl is null or whitespace.

GetToolsKey

Gets the cache key for a tools entry.

Syntax

public string GetToolsKey(string serviceUrl, string optionsHash)

Parameters

NameTypeDescription
serviceUrlstringThe OData service URL.
optionsHashstringThe hash of the tool generation options.

Returns

Type: string The cache key for the tools.

Exceptions

ExceptionDescription
ArgumentExceptionThrown when serviceUrl is null or whitespace.

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.CachingConfiguration other)

Parameters

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

Exceptions

ExceptionDescription
ArgumentNullExceptionThrown when other is null.

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 caching 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.