SoFunction
Updated on 2025-03-07

Introduction to the use of Cache in

Cache is cache. I think many people have the same first impression of him as me, and I feel that he can improve the performance and running speed of the system. indeed. This is indeed the original intention of Net launching cache. So how does cache improve system performance and running speed? Can using cache improve performance in all cases? Is it better to use cache? I have some experience in recent research and development projects. I write them down as a summary and hope to discuss them with you. I hope you will criticize and correct any mistakes.

How it works

Cache is a common memory slice allocated on the server.

The so-called public refers to cache as long as it is created, all client browsers can access it through background code. It targets all users. Relatively speaking, session is also a piece of memory on the server, but it targets a single user. It is a memory block of the server, which means that each cache occupies server resources once it is created. So from this point of view we can say: the more caches, the better.

cache has a time limit. If it exceeds the expiration time set by the server, it will be recycled by the server.

Can store all objects

How to create and destroy

Create a cache

exist. Created in the Net environment through the (string key, object o) method. where key represents the ID of the cache, and o represents the object stored in the cache.

Destroy cache.

Pass method (string key), where key represents the ID of cache.

Call cache.

Cache supports packing/unboxing operations. If you can save a DataSet object ds into the Cache through ("dsCache", ds), you can access it by unboxing DataSet ds = (DataSet)Cache["dsCache"].

3. When to use cache

Cache is generally used in places where data is relatively fixed and is used more frequently. For example, product information can be stored in the purchase and sales storage system, and the user can call the cache when calling the product information. This greatly reduces the interaction between the user and the database and improves the performance of the system. On the contrary, cache is not suitable for use where data changes quickly and the use range is very narrow. For example, deposit a specific purchase order into the cache.

Notes on calling

Cache has time limits. If the expiration time set by the server exceeds the server, it will be recycled by the server. When the cache is recycled, the corresponding memory block will be cleared. When the object is accessed through cache["cachekey"] again, the null value is returned. Therefore, the following call will have an exception