This article is a mirror article of machine translation, please click here to jump to the original article.

View: 5409|Reply: 5

[.NET Core] ASP.NET Core (18) Customize a simple OutputCache output cache

[Copy link]
Posted on 5/7/2023 9:42:06 PM | | | |
Requirements: Have one in the .NET FrameworkOutputCacheAttributeThe feature (which is used to mark the operation method of caching its output) stores frequently accessed and infrequently changing data in memory and outputs response content directly, which can improve the concurrency performance of the website and reduce the pressure on the server and database. This feature was only added back in .NET 7.





ASP.NET Output cache middleware in Core:The hyperlink login is visible.

The principle of output caching: each request first determines whether it exists in the cache, if it does not exist, writes the content of the response to the cache and then outputs the response, if the cache exists, the data output response is directly obtained from the cache. via output cacheReducing querying the database, reducing some logical operations, and fetching directly from the cache improves both concurrency and responsiveness

Since there is no OutputCacheAttribute feature in .NET 6, we can implement a simple output cache ourselves.


In the absence of an output cache, the stress test results are as follows (The project database is connected to the Hong Kong server):



Stress test results: Only 10 concurrency per second allowed (slow in database transfer).

To try to add an output cache, first, create a new OutputCacheAttribute feature, the code is as follows:

Create a new OutputCacheMiddleware middleware to block the request, and the code is as follows:

Add the UseOutputCacheExtensions middleware to Program.cs with the following code:

Finally, add the feature to the controller method with the following code:

Again with pressure testing, it can be achievedMore than 10,000 concurrency per second, as shown in the figure below:

cassowary.exe run -u http://localhost:5222/zh-cn -c 50 -n 100000



The Cassowary tool for HTTP request stress testing
https://www.itsvse.com/thread-10557-1-1.html
(End)




Previous:[Turn]. NET 8 Newly Added High-Performance Types
Next:.NET Core high-performance queue Channels is used
 Landlord| Posted on 5/7/2023 9:50:45 PM |

review

ASP.NET Core (17) integrates MiniProfile application performance analysis
https://www.itsvse.com/thread-10571-1-1.html

ASP.NET Core (16) Dependent on injection of dynamic registration services
https://www.itsvse.com/thread-10560-1-1.html

ASP.NET Core (XV) uses HttpClient to send HTTP requests
https://www.itsvse.com/thread-10311-1-1.html

ASP.NET Core (fourteen) is based on the SkiaSharp image captcha
https://www.itsvse.com/thread-10287-1-1.html

ASP.NET Core (XIII) to determine whether it is an Ajax request or not
https://www.itsvse.com/thread-10284-1-1.html

ASP.NET Core (twelve) front-end JS, CSS bundling, and compression
https://www.itsvse.com/thread-10282-1-1.html

ASP.NET Core (XI) endpoint route adds middleware to display all DI services
https://www.itsvse.com/thread-10269-1-1.html

ASP.NET Detailed explanation of Configuration priorities in Core(10).
https://www.itsvse.com/thread-10265-1-1.html

ASP.NET Detailed explanation of the Middleware middleware of Core (9).
https://www.itsvse.com/thread-9647-1-1.html

ASP.NET Detailed explanation of Core Middleware
https://www.itsvse.com/thread-8126-1-1.html

ASP.NET pit of the default parameters of the Swagger UI in Core(8).
https://www.itsvse.com/thread-9640-1-1.html

ASP.NET Core (7) In-depth analysis of the framework source code
https://www.itsvse.com/thread-9601-1-1.html

ASP.NET Core (VI) DI manually obtains the method of injecting objects
https://www.itsvse.com/thread-9595-1-1.html

ASP.NET Core (five) is based on CAP distributed transactions
https://www.itsvse.com/thread-9593-1-1.html

ASP.NET Core(4) filter unified ModelState model validation
https://www.itsvse.com/thread-9589-1-1.html

ASP.NET Core (iii) Dynamically create instances using ActivatorUtilities
https://www.itsvse.com/thread-9488-1-1.html

ASP.NET Core (2) Restart the application by code
https://www.itsvse.com/thread-9480-1-1.html

ASP.NET Core (1) uses Redis caching
https://www.itsvse.com/thread-9393-1-1.html
 Landlord| Posted on 5/7/2023 9:53:14 PM |
About the asp.net OutputCache cache flushing disable setting
https://www.itsvse.com/thread-5843-1-1.html

ASP.NET OutputCache cache web.config parameter configuration
https://www.itsvse.com/thread-4917-1-1.html

mvc cache the correct usage of the OutputCache property VaryByParam
https://www.itsvse.com/thread-3488-1-1.html
Posted on 5/8/2023 9:37:41 AM |
Learn to learn
Posted on 5/17/2023 10:37:28 AM |
HTTP status code: 204 No Content

204 No Content: The server successfully processed the request but returned nothing.

Writing to the response body is invalid for responses with status code 204.
 Landlord| Posted on 6/22/2023 1:20:52 PM |
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com