Different ways to cache application data in asp net Part 127

preview_player
Показать описание
Text version of the video

Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help.

Slides

All ASP .NET Text Articles

All ASP .NET Slides

All Dot Net and SQL Server Tutorials in English

All Dot Net and SQL Server Tutorials in Arabic

Cache["Cache_Key"] = Data_To_Cache

In this video we will discuss about
1. Different ways to cache application data
2. Removing an item from cache
3. Similarities and difference between cache and application state

Apart from caching data, using assignment, there are 2 other ways to cache application data
1. Using "Cache" object's Insert() method
2. Using "Cache" object's Add() method

Caching application data, using "Cache" object's Insert() method:
Cache object's, Insert() method has got 5 overloaded versions. Depending on application requirement, we can choose the overloaded version that best suits our needs. The simplest overloaded version, takes 2 parameters.
1. The Cache Key and
2. The data that we want to cache

In Part 126, we cached products dataset, using assignment as shown below
Cache["ProductsData"] = ds;

The same thing can be achieved, using cache object's "Insert()" method, as shown below.
Cache.Insert("ProductsData", ds);

We will discuss about other overloaded versions of "Insert()" method in a later video session.

Caching application data, using "Cache" object's Add() method:
Adding application data, to the cache object, using "Add()" method is similar to "Insert()" method. As "Insert()" method has got several overloaded versions, some of the parameters are optional. Where as, "Add()" method does not have any overloads, and hence, all parameters must be specified.
Cache.Add("ProductsData", ds, null, System.Web.Caching.Cache.NoAbsoluteExpiration,System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.Default, null);

We will discuss about "absolute expiration", "sliding expiration", and CacheItemPriority in a later video session.

Be cautious when dealing with cache keys: Assigning a value to a cache key, that is already being used will silently overwrite the existing value, without any warnings. For example
The value stored in "MyKey" is "Value1"
Cache["MyKey"] = "Value 1";

The following line will silently overwrite "MyKey" value to "Value 2"
Cache["MyKey"] = "Value 2";

To Remove an item from cache explicitly, use Remove() method. The following line would remove the cache item with key "MyKey"
Cache.Remove("MyKey");

Please Note: An item may be removed automatically, from cache, when any of the following conditions are true
The cached item has expired.
The cache is full.
There is a cache dependency, and the item, that the cache object is dependent on has changed.

In a way, Cache object is similar to Application state. The objects that we store in application state variables are available anywhere within a Web application. Objects stored in cache are also available anywhere within a Web application. But the difference is that, items stored in cache can expire, where as items in application state will never expire.
Рекомендации по теме
Комментарии
Автор

Dear Venkat sir, your videos are very useful... and can you please let me know the below clarifications...
01) Where we can find Cache information
02) Which format it will be stored and
03) What is the default time for Cache?
04) How we know Cache is full?

venkatasairamakrishnatunug
Автор

hi venkat, in part 126...i learned how to cache application data using cache key...may i know how long the data exists in cache....can v set expiration time to cached data....could u tell eme

harikaaakutota
Автор

Hi,
In caching the application data. It will be stored on the server right!?

danielagomes
Автор

thank alot for that series,

i have problem my cached data disapper after 2 hit i don't know why ? i host it on iis 10, please help ?

what is the resoan what configration i should do ?
☹☹☹

mragab
Автор

Sir i want to share a link, where you can find how the computer generate our data in 0's and 1's. Sorry if you know it already...

kiranpedamkar
welcome to shbcf.ru