asp + MsSQL2000 analog Html static file caching

It is written in JavaScript asp, I can not read over.

In fact, I do not want to send out, because I boast of too few people.
If you later want to point the classic thinking weird code to boast me a few words.

The purpose of this code is:
do not create a cache wit Html asp file server to save consumption,
the direct use asp to simulate Html cache wit, make the code easier.

Benefits:
1. much better than a simple asp file, open the cache wit, both times without any database queries repeatedly.
2 and change the code easier, Html static dynamic code change once again have to survive all the files.

Disadvantages:
1 static contrast Html files, cache simulation him more steps
but also by the actual static Html IIS cache to execute judgment, but the ASP efficiency is too slow, so this becomes a disadvantage if ASPX then this. points can be ignored
2. when each simulation cache, will go to inquire whether a asp files that have changed, there will be a query IIS, as well as a query component, more than one query default asp.
the only query static files whether a static file changes.
3. each simulation will query the database to get a TimesTamp data.

Modify the code by:
1. Modify the eighth line data connections.
2. Add the database field names for the database field types TimesTamp TimesTamp any field in the database
3. Modify 38.82 row database connection.


<%@LANGUAGE="JAVASCRIPT"%>
<%
var Conn = {}
Conn.Id = function(DaData){
        var Result = + ( ( DaData + "" ) || 0 )
        return ( Result > 0 ) ? Result : 0
}
Conn.ConnText = "driver={SQL Server}; server=127.0.0.1; uid=sa; pwd=; database=DADA"
Conn.Create = function(){
        try {
                Conn.Object = new ActiveXObject("ADODB.Connection");
        } catch(Error) {
                Conn.Object = null
                Response.Write("无法创建数据库对象。" + Error )
                Response.End()
        }
        try {
                Conn.Object.Open(Conn.ConnText)
        } catch(Error) {
                = Null Conn.Object
                Response.Write ( "Unable to open the database." Error +)
                Response.End ()
        }
}


Conn.Create()

// Get the last modified file asp milliseconds
var = new new HaFso the ActiveXObject ( "Scripting.FileSystemObject");
var = HaFile HaFso.GetFile (the Server.MapPath (the Request.ServerVariables ( "SCRIPT_NAME")));
var = new new HaAspModifiedTime a Date (HaFile.DateLastModified) .getTime ()
var HaFile = null
var = null HaFso


// Check whether the database is changed
var HaRs = Conn.Object.Execute ( "SELECT CAST ([TimesTamp] AS int) AS [TimesTamp] FROM [User] WHERE ID = '" + Conn.Id (Request ( "Id") ) + " '")
// 9 up to 15 may be converted to a date, but up to 21 digital TIMESTAMP, 18446744073709551615
var HaTimesTamp HaRs.Fields + = ( "TIMESTAMP") + HaAspModifiedTime
HaTimesTamp = the parseInt ((HaTimesTamp / 1000000000000 - (HaTimesTamp / 1000000000000 >> 0)) * 1000000000000000)
HaRs.Close ()

var HaIfModifiedSince = new Date(HaTimesTamp).toUTCString()
var HaIfNoneMatch = "000000000000000000".substr(HaTimesTamp.toString(36).length) + HaTimesTamp.toString(36).toUpperCase()
var HaHTTP_IF_MODIFIED_SINCE = new Date(Request.ServerVariables("HTTP_IF_MODIFIED_SINCE")).toUTCString()
var HaHTTP_IF_NONE_MATCH = ( Request.ServerVariables("HTTP_IF_NONE_MATCH") + "" ).toUpperCase()

if ( HaIfModifiedSince == HaHTTP_IF_MODIFIED_SINCE ) {
        Response.Status = 304
        Response.AddHeader("ETag", HaIfNoneMatch)
        Response.End()
}else{
        Response.Status = 200
        Response.AddHeader("Last-Modified", HaIfModifiedSince)
        Response.AddHeader("ETag", HaIfNoneMatch)
}


//测试
if ( false ) {
        Response.Write( new Date().getTime() + "<br>" )
        Response.Write( "If-Modified-Since : " + HaIfModifiedSince + "<br>" )
        Response.Write( "ETag : " + HaIfNoneMatch + "<br>" )
        Response.Write( "HTTP_IF_MODIFIED_SINCE : " + HaHTTP_IF_MODIFIED_SINCE + "<br>" )
        Response.Write( "HTTP_IF_NONE_MATCH : " + HaHTTP_IF_NONE_MATCH + "<br>" )
}


Here // The following is a content code for
the Application ( "Number The") = (the Application ( "Number The") || 0) +. 1
Response.Write ( "times the SQL query:" + Application ( "Number" ) + "<br > ")

var HaDate = new Date()
Response.Write(
"当前数据缓存日期:"
+ HaDate.getFullYear() + "-" + HaDate.getMonth() + "-" + HaDate.getDay() + "-" + HaDate.getDate()
+ " "
+ HaDate.getHours() + ":" + HaDate.getMinutes() + ":" + HaDate.getSeconds() + ":" + HaDate.getMilliseconds()
)

var HaRs = Conn.Object.Execute("SELECT * FROM [User] WHERE ID = '" + Conn.Id(Request("Id")) + "'")
Response.Write("<table border=\"1\" cellpadding=\"5\" cellspacing=\"0\" bordercolor=\"#CCCCCC\">")
Response.Write("<tr>")
for ( var i = 0; i < HaRs.Fields.Count ; i++ ) {
        Response.Write( "<td>" + HaRs.Fields(i).Name + "</td>" )
}
Response.Write("</tr>")
Response.Write("<tr>")
for ( var i = 0; i < HaRs.Fields.Count ; i++ ) {
        Response.Write( "<td>" + (HaRs.Fields(i).Value || " ") + "</td>" )
}
Response.Write("</tr>")
Response.Write("</table>")
HaRs.Close()
%>

Reproduced in: https: //www.cnblogs.com/aspphpvbs/archive/2013/04/21/3034276.html

Guess you like

Origin blog.csdn.net/weixin_34191845/article/details/93701725
Recommended