---
title: Query caching
slug: cms-12/docs/caching
docTags: 
createdAt: 2026-08-10T15:55:59.000Z
---

Query caching is useful, for example, to make search-based implementations more resilient. Search requests can be cached for a certain duration using the `StaticallyCacheFor` method, which accepts a timespan. No cache key is required because the search request will generate one.

The following code returns a previously cached result or executes the query and caches the result for five minutes.

```csharp
var result = client.Search<BlogPost>()
    .StaticallyCacheFor(TimeSpan.FromMinutes(5))
    .GetResult();
```

You can also cache results with a dependency (`System.Web.Caching.Dependency`) using an overload to the `StaticallyCacheFor` method.

:::hint{type="info"}
**Note**
From `Episerver.Find` 16.3.0, you can configure the default cache for search requests.

- Add `DefaultSearchCacheDuration` (in seconds) to the `Find` section. This applies to your request whenever you call `GetResult`/`GetResultAsync` or `GetContentResult`/ `GetContentResultAsync`.
- The `DefaultSearchCacheDuration` is replaced by `StaticallyCacheFor` if set.
- If you do not set either `StaticallyCacheFor` or `DefaultSearchCacheDuration`, your search request is cached in 10 minutes by default. You can remove the default value by setting `DefaultSearchCacheDuration: 0`.
:::

**Related blog post:** [Common caching pitfalls](https://world.optimizely.com/blogs/dada/dates/2019/1/common-find-caching-pitfalls/)
