In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to optimize ASP.NET local cache". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn how to optimize ASP.NET local cache.
One: common solutions for local caching
There are several types of solutions for the above requirements:
1. Client Side Includes (CSI): dynamically include the content of another page by means of frame, iframe, javascript, javacript+ajax, etc. Javascript libraries such as the popular jquery have good support for this.
Advantages: it can make use of the parallel processing and loading mechanism of the browser client; through the browser cache mechanism, it can reduce the network transmission time and improve the performance; the computing on the client side can reduce the pressure on the server side.
Disadvantages: search engine optimization problems; javascript compatibility issues; client-side cache may cause server-side content updates can not take effect in time; XSS and other security risks
2. Server Side Includes (SSI):
Advantages: SSI technology is a general technology, which is not limited by specific language, and only needs to be supported by Web server or application server. Ngnix, Apache, Tomcat, Jboss and so on all have good support for it.
Disadvantages: SSI cannot directly include the url of other servers in syntax (of course, it can also be implemented through redirect, etc.), so it is relatively inflexible in an environment that needs to make full use of cache and load balancing.
Of course, if you do not use a separate cache server, but use Ngnix, use Ngnix to support SSI and Memcached, and achieve page caching through NginxHttpSsiModule and NginxHttpMemcachedModule. But compared with professional cache servers (such as Varnish), Ngnix as a cache server is only suitable for small and medium-sized occasions.
3. Use ASP.NET 's fragment cache
You can use the user control to segment the page and write cached statements in the ascx file instead of in the aspx file, so that ASP.NET can cache only the output of the ascx fragments.
Cons: fragment caching does not support the Location feature; the only legal place for cached page fragments is the web server. This is because fragment caching is a new feature in ASP.NET, so browsers and proxy servers do not support it. Because it is not a W3C standard, proxy servers such as SQUID and VARNISH do not support it.
4. Edge Side Includes (ESI):
Edge Side Includes (ESI) and Server Side Includes (SSI) are similar in function. SSI requires a special file suffix (shtml,inc). ESI can include remote server files directly through URI, and ESI is more suitable for caching entire pages or page fragments on the cache server, so ESI is especially suitable for caching. What this article is going to introduce is the way ESI supports local caching.
Pros: ESI is a W3C standard supported by the popular cache server SQUID,Varnish.
Second: ASP.NET implementation of ESI
The purpose of this paper is to describe the implementation of ESI local cache. Front desk of main page (test1.aspx):
This is the end of the local cache.
For the background of the main page, please refer to the previous section, which adopts a caching strategy for the main page, that is, the esi:include logo is used in the page.
Foreground of the included page (test2.aspx):
Pages in the local cache:
The background of the included page does not need to process anything, that is, no caching strategy is added to it, and the page is real-time.
The VARNISH configuration file is as follows:
Backend default {.host = "192.168.0.77"; .port = "80";} sub vcl_fetch {remove beresp.http.Set-Cookie; if (req.url ~ "test1.aspx") {esi;} if (req.url ~ "test2.aspx") {return (pass);}} sub vcl_recv {remove req.http.Cookie; # remove req.http.Accept-Encoding; # remove req.http.Vary } sub vcl_hit {if (req.http.Cache-Control~ "no-cache" | | req.http.Cache-Control~ "max-age=0" | | req.http.Pragma~ "no-cache") {set obj.ttl=0s; return (restart);} return (deliver);} sub vcl_deliver {if (obj.hits > 0) {set resp.http.X-Cache = "HIT";} else {set resp.http.X-Cache = "MISS";}}
Two judgments have been added to the vcl_fetch function above, which means that if you encounter test1.aspx, you will deal with the esi identity, and if you encounter test2.aspx, you will directly ignore it and let the backend IIS handle it.
It is worth noting that the-p option has been added to the startup command (this is a small problem with varnish, please refer to it, not listed here):
Varnishd-a: 8011-T: 8088-f c:/varnish/etc/default.vcl-p esi_syntax=0x1-s file,c:/varnish/var/cache,100M
Three: effect
After starting varnish, we found that for test2.aspx, because we use esi to include it, and test2.aspx does not cache it, so during the cache validity period of test1.aspx, with each refresh, the content of test1.aspx remains unchanged, but the included test2.aspx area will be refreshed in real time.
Thank you for reading, the above is the content of "how to optimize ASP.NET local cache". After the study of this article, I believe you have a deeper understanding of how to optimize ASP.NET local cache, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.