November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
Firstly I would not suggest using GetContentResult as this reloads data from the IContentRepository causing a database hit on each result. This affects performance and uses lots of resources.
You can read about it in my blog https://world.optimizely.com/blogs/scott-reed/dates/2019/3/episerver-find---performance-reloading-custom-data-and-getcontent-vs-getcontentresult/
You should just use the GetResult and use projections.
Caching wise if you use StaticallyCacheFor off the back of the search you can pass in a cache dependeny which you can invalidate. Read here https://world.optimizely.com/forum/developer-forum/Search/Thread-Container/2015/8/invalidate-cached-results-of-quotstaticallycacheforquot/
@Scott: I agree on advise to go with GetResult and projection, since you then also limit data sent over the wire. But... this phase: "I would not suggest using GetContentResult as this reloads data from the IContentRepository causing a database hit on each result. This affects performance and uses lots of resources."
Optimizely CMS automatically caches objects that are requested from the API, such as content instances through IContentRepository. The object cache is an in-memory cache and stores only read-only objects for better performance. So the database will not be hit on each result.
It should automatically invalidate the cache (I guess what you meant for "burst") if you publish a content. Did you check if the newly published content gets indexed properly?
Hmm, It is more complicated than I thought. Apparently GetContentResult caches the search result with the dependency to IContentCacheKeyCreator.RootKeyName. So it means it is most likely not properly invalidated when you publish a content. You can, in theory, remove that cache key to invalidate the search result cache, but it also invalidates all content cache, so that is really a nuke option. Hmm, I will need to talk with Search team about this
@scott : I am trying to add cacheDependency in StaticallyCacheFor() as suggested in your blog, and then invalidate it on publish event of a page, but cache is not getting stored in HttpRuntimeCache. Hence I am unable to invalidate it as well. Below is the code -
var searchQuery = _searchClient.Search()
searchQuery = searchQuery .PublishedInLanguage(language)
.FilterOnReadAccess()
var cacheDependency = new CacheDependency(null, new[] { CacheKeys.searchKey })
var queryResults = searchQuery .StaticallyCacheFor(TimeSpan.FromMinutes(5), cacheDependency) .GetResult()
var keyValue= HttpRuntime .Cache .Get(CacheKeys.searchKey)
keyValue is coming null, and hence not getting removed when I try this on publish event of the page -
HttpRuntime.Cache.Remove(CacheKeys.searchKey);
Is there anything else that needs to be added? I am currently using FIND v 13.2.6.
Any suggestions would be helpful. Thanks!
Currenlty, we are caching the query results for 2 hours using GetContentResult() and looking for a way to burst the GetContentResult() cache to fetch latest results.
We are using EPiserver.CMS.FIND 13.2.6.