> For the complete documentation index, see [llms.txt](https://vostok.gitbook.io/configuration/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://vostok.gitbook.io/configuration/concepts-and-basics/caching-and-performance.md).

# Caching and performance

[Configuration providers](/configuration/concepts-and-basics/configuration-provider.md) cache [bound](/configuration/concepts-and-basics/binding-nodes-to-models.md) settings for each `(type, source)` pair where sources are compared by reference. Caching ensures a solid performance level: only the first **Get** call is somewhat expensive while all the subsequent ones are extremely cheap. The cache is automatically updated when the underlying [source](/configuration/concepts-and-basics/configuration-sources.md) issues new data.

```
provider.Get<MySettings>(); // may block and incurs binding costs

provider.Get<MySettings>(); // instantly returns a cached object

// ... the source issues a data update ...

provider.Get<MySettings>(); // instantly returns the old cached object

// ... the cache is automatically updated in background...

provider.Get<MySettings>(); // instantly returns an updated cached object
```

{% hint style="info" %}
Due to caching, [configuration provider](/configuration/concepts-and-basics/configuration-provider.md) instances should be reused as much as possible. Ideally there should be just one singleton instance in the application.
{% endhint %}

{% hint style="warning" %}
Special care should be taken when using **Get** and **Observe** methods with short-lived source instances passed on per-call basis. This could cause poor performance due to cache misses and even lead to cache overflow events. Overflow events may cause violations of [error handling guarantees](/configuration/concepts-and-basics/error-handling.md). Default cache capacity [is 50](https://github.com/vostok/configuration/blob/master/Vostok.Configuration/ConfigurationProviderSettings.cs#L50) but can be tuned in provider settings:

```
var settings = new ConfigurationProviderSettings 
{
    MaxSourceCacheSize = 100_000
};

var provider = new ConfigurationProvider(settings);
```

This pitfall is easy to fall into as all of the source-related extensions ([combine](/configuration/basic-scenarios/combine-sources.md), [scope](/configuration/basic-scenarios/scope-sources.md), [transform](/configuration/advanced-scenarios/transform-sources.md), etc) return decorators that are treated as distinct sources. The only viable solution is to cache these derivative sources. &#x20;
{% endhint %}

### Related pages

{% content-ref url="/pages/-M6UQugcsHv63ilSF945" %}
[Configuration provider](/configuration/concepts-and-basics/configuration-provider.md)
{% endcontent-ref %}

{% content-ref url="/pages/-M6UVoFcHYxcwBpGwH8S" %}
[Log settings updates](/configuration/basic-scenarios/log-new-settings.md)
{% endcontent-ref %}

{% content-ref url="/pages/-M6UVVWxjimC0yLfXc\_P" %}
[Obtain settings from provider](/configuration/basic-scenarios/obtain-settings-from-provider.md)
{% endcontent-ref %}

{% content-ref url="/pages/-M6UVXzWRFlbId1t7QdO" %}
[Observe settings via provider](/configuration/basic-scenarios/observe-settings-via-provider.md)
{% endcontent-ref %}
