World is now on Opti ID! Learn more

manh_nguyen
Sep 4, 2024
  42
(0 votes)

Default caching on search request on Search & Navigation

For the better performance, Search & Navigation .Net client has provided StaticallyCacheFor method for caching your search result in a specific of time span. It really useful when you perform a real-time search response to your users without a request.

We now including a default caching duration for your search request in-case StaticallyCacheFor make your code more cumbersome 😃

This can be done by setting DefaultSearchCacheDuration (in seconds) in Find section and it applies to all request that calling to GetResult or GetContentResult (in both asynchronous and synchronous version of API).

    "Find": {
      "DefaultIndex": "your_index",
      "ServiceUrl": "https://service.find.episerver.net/your_private_key",
      "DefaultSearchCacheDuration": 300
    }

In the example above you config for default caching in 5 minutes, but you can overide this default value for some specific request by using StaticallyCacheFor, this will replace default value as highest priority.

For example:

//this response will cache the search result by 5 minutes as DefaultSearchCacheDuration is set to 300 seconds.
var responseCacheInDefault = await SearchClient.Instance
.Search<IContent>().For("samsung")
.GetResultAsync();

//but this response will be cached in 15 minutes
var responseCacheOverridden = await SearchClient.Instance
.Search<IContent>().For("iphone")
.StaticallyCacheFor(TimeSpan.FromMinutes(15))
.GetResultAsync();

If you don't have DefaultSearchCacheDuration in the Find config and don't also set StaticallyCacheFor, your search response will automatically cache in 10 minutes.

But maybe you ask for "what if I don't need any default search cache?", just set DefaultSearchCacheDuration to zero.

For more details please go to our documents for developers.

Please don't hesitate to contact us if you have any question or feedback.

Sep 04, 2024

Comments

Please login to comment.
Latest blogs
Make Global Assets Site- and Language-Aware at Indexing Time

I had a support case the other day with a question around search on global assets on a multisite. This is the result of that investigation. This co...

dada | Jun 26, 2025

The remote server returned an error: (400) Bad Request – when configuring Azure Storage for an older Optimizely CMS site

How to fix a strange issue that occurred when I moved editor-uploaded files for some old Optimizely CMS 11 solutions to Azure Storage.

Tomas Hensrud Gulla | Jun 26, 2025 |

Enable Opal AI for your Optimizely products

Learn how to enable Opal AI, and meet your infinite workforce.

Tomas Hensrud Gulla | Jun 25, 2025 |

Deploying to Optimizely Frontend Hosting: A Practical Guide

Optimizely Frontend Hosting is a cloud-based solution for deploying headless frontend applications - currently supporting only Next.js projects. It...

Szymon Uryga | Jun 25, 2025

World on Opti ID

We're excited to announce that world.optimizely.com is now integrated with Opti ID! What does this mean for you? New Users:  You can now log in wit...

Patrick Lam | Jun 22, 2025

Avoid Scandinavian Letters in File Names in Optimizely CMS

Discover how Scandinavian letters in file names can break media in Optimizely CMS—and learn a simple code fix to automatically sanitize uploads for...

Henning Sjørbotten | Jun 19, 2025 |