![]() ![]() vary-by-user: must be set to true when we display specific data for the logged in user, such as the profile box containing the name and photo.vary-by-query: the content is generated and cached when the querystring key is changed.vary-by-route: is enhanced with the name of a route parameter, for example id, to indicate that the content must be regenerated when the indicated property change.Some requirements are covered by the vary-by- attributes listed below: We may need to update our cached object based on some variables. Each time the content is read from the cache, its removal is postponed.Īnother customizable aspect concerns the possibility to configure the caching criterion. expires-sliding: a TimeSpan that indicates a period of inactivity should also be used.expires-after: to be evaluated with a TimeSpan to indicate a period of time, after which, the content must be regenerated.In the previous snippet, you can also see how to manage the expiring period of the object in cache, through the attribute expires-on. Re-set the cache to be reloaded in 35minĪnother interesting feature available with Memor圜acheEntryOptions class is the one that permits us to register callbacks, to be executed when an item is removed from the Component.InvokeAsync("BlogPosts", new ) Var places = await GetLongGeneratingData() Ĭache.Set(CACHE_KEY_PLACES, places, TimeSpan.FromMinutes(40)) Private async void RefreshAllPlacesCache_PostEvictionCallback(object key, object value, EvictionReason reason, object state) ![]() Method triggered by the cancellation token that triggers the PostEvictionCallBack Mo.AddExpirationToken(new CancellationChangeToken(new CancellationTokenSource(TimeSpan.FromMinutes(35)).Token)) Ĭache.Set(CACHE_KEY_PLACES_RESET, DateTime.Now, mo) Mo.RegisterPostEvictionCallback(RefreshAllPlacessCache_PostEvictionCallback) This method adds a trigger to refresh the data from background use both absolute and sliding expirationĪbsoluteExpirationRelativeToNow = TimeSpan.FromDays(30), _cache.Set("key", item, new Memor圜acheEntryOptions sliding expiration (scade se non viene letta per 7 giorni) _cache.Set("key", item, TimeSpan.FromDays(1)) You can enable the in-memory cache in the Startup class as shown in the code snippet below. ![]() The ASP.NET in-memory cache is a feature we can incorporate in our application using the method ConfigureServices. In this article, we will look in detail at the in-memory cache, whereas the distributed cache will be examined in a future article. All the other techniques, you may have heard about, are implementations of these two interfaces. These two interfaces represent the built-in mechanism for caching in. In this article, we will see what does ASP.NET Core make avalable for caching. The frequency is a business requirement of our application. If using best practices when we write code it’s not enough, we surely need to use the caching to nudge our applications.Ĭaching consists in storing somewhere those information, that change less frequently. I believe it has happened to everyone, in our job, to receive requests from clients, or feedback from users of our applications, to improve responsiveness. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |