Recommended: Brief analysis of asp component-free upload and insert it into the database The following is the referenced content: %Response.Buffer = True Server.ScriptTimeOut=9999999 On Error Resume Next %>
It has been 7 years since ASP was released, and its ASP technology has been quite mature. Since Microsoft launched ASP.NET, it has gradually stopped updating the ASP version. But since there are many people who are still used to using ASP to develop websites, again I will use a simple example to illustrate how to use Cache in ASP.
Simply put, the basic principle of using Cache is to store frequently needed and expensive data in memory for a certain period of time so that this data can be accessed directly globally. For example, some data needs to be queried from multiple tables in the database, and almost every page calls this data.
The best implementation in this case is to cache this part of the data. A simple implementation in ASP is to encapsulate the final expression form of this data (such as HTML stream) in string and store it in the ASP built-in object Application (this article mainly discusses dynamic cache, and simple ASP applications will be omitted). The advantage of this is that this HTML can be called globally throughout the website, and the Application is in memory, so there is no need to query the database anymore, which speeds up the response time and saves server load. Of course, this is at the expense of memory, and it is a typical example of exchanging space for time.
Although there are many benefits to using this method, when encountering frequently changing data sources (databases), this method may no longer be applicable, because ASP Application objects have a disadvantage, which is that they cannot automatically change with the changes of the data source, or control the refresh interval. So developers need to program to implement dynamic cache. Of course, when programming, you can update the Appplication once when all operations are changed in data source (database). This keeps the data source (database) consistent. This will require more problems to be considered in programming and will easily miss details. So I don't recommend this method except for specific situations.
I think the best way in ASP is to use programming to refresh the cache regularly, which means setting an expiration time for the stored in the Application. Of course, the Application object does not have such an ExpireTime property in ASP. This needs to be implemented using programs.
| The following is the quoted content: default.asp <%@Language=VBScript%> <%Option Explicit%> <%Response.Buffer=True%> <!--#include file = conn.asp--> <!--#include file = GetCache.asp--> <HTML> <HEAD> <TITLE>ASP Cache Demo</TITLE> <META HTTP-EQUIV=Content-Type CONTENT=text/html; charset=gb2312> </HEAD> <BODY> <h4>Refresh Cache every 10 seconds:</h4> <% response.Flush GetHTMLStream response.Write HTMLStream %> </body> </html> |
| The following is the quoted content: getcache.asp <% Const CACHE_DEFAULT_INTERVAL = 30 'Refresh cache every 30 seconds Dim HTMLStream Dim IsExpires IsExpires = CacheExpires Function CacheExpires Dim strLastupdate Dim result strLastupdate = Application(Lastupdate) If (strLastupdate = ) Or (CACHE_DEFAULT_INTERVAL < DateDiff(s, strLastupdate, Now)) Then result = true SetLastupdateTime Else result = false End If CacheExpires = result End Function Sub SetLastupdateTime Application.Lock Application(Lastupdate) = CStr(now()) Application.UnLock End Sub Sub GetHTMLStream If IsExpires Then updateHTMLStream End If HTMLStream=Application(CACHE_HTMLStream) End Sub |
| The following is the quoted content: Sub updateHTMLStream dim d d = FetchHTMLStream Application.Lock Application(CACHE_HTMLStream) = d Application.UnLock End Sub Function FetchHTMLStream Dim rs ,strSQL, strHTML Set rs = createObject(ADODB.Recordset) strSQL = select categoryID , categoryname from categories rs.Open strSQL, strConn,adOpenForwardOnly,adLockReadOnly strHTML = strHTML & <select name=slt_search> while (not rs.EOF) strHTML = strHTML & <option> strHTML = strHTML & rs.Fields(categoryname) strHTML = strHTML & </option> rs.MoveNext wend strHTML = strHTML & </select> rs.Close Set rs = Nothing FetchHTMLStream = strHTML End Function %> |
| The following is the quoted content: conn.asp <!--METADATA NAME=Microsoft ActiveX Data Objects 2.5 Library TYPE=TypeLib UUID={00000205-0000-0010-8000-00AA006D2EA4}--> <% dim strConn strConn = Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Northwind %> |
Share: How to use ASP to display GIF images of ACCESS database Write: 1: Read the gif image file into memory (a variable strTemp). 2: Write to the database. The following is the quoted content: Dim binTmp() As Byte Dim conn As ADODB.Conn