The built-in set of application object can be used by default by application ("key") to store contents designed for simple types.
However, application. contents cannot store objects or vbs arrays, but it cannot even store arrays in JavaScript.
When using application. Contents, you can only use ugly ones such:
For (VAR I = 0; I <15000; I ++ ){
Application. Lock ();
// Application. Contents (I) = "sdfdsffdsaf ";
Application (I) = "sdfdsffdsaf ";
Application. Unlock ();}
234 strings are stored in application. contents, which takes ms in total.
After using application. staticobjects:
Define a dictionary as staticobject to store data, because staticobject cannot be accessed directly.
<Object ID = "dict" runat = "server" Scope = "application" progid = "scripting. Dictionary"> </Object>
Scripting. dictionary itself is fast and will not significantly affect the speed of comparing staticobjects sets.
Dictionary speed:
VaR d = new activexobject ("scripting. Dictionary ");
For (VAR I = 0; I <15000; I ++ ){
D. Item (I) = "sdfdsffdsaf ";}
172 million times of interpolation, Ms
Of course, the custom object var d = new object (); D [I] =... is faster, times as long as 80-90 ms, but the function is much weaker, so the dictionary is used.
See the formal test below
For (VAR I = 0; I <15000; I ++ ){
Application. Lock ();
Application. staticobjects ("dict"). Item (I) = "sdfdsffdsaf ";
Application. Unlock ();}
As long as 6953 ms, It is preliminarily determined that the access speed of the staticobjects set cannot meet the cache requirements. This speed is almost the same as that of reading SQL Server 2000 from ADO oledb.
However, you do not want to give up immediately because staticobjects can store objects, while dictionary can also store other objects. This can be used as cache objects, not just data.
I put another object in application. staticobjects ("dict:
Application. staticobjects ("dict"). Item ("O") = new object ();
For (VAR I = 0; I <15000; I ++ ){
Application. Lock ();
Application. staticobjects ("dict"). Item ("O") [I] = "sdfdsffdsaf ";
Application. Unlock ();}
6656 Ms, A little faster. The slow speed of a layer of objects is not complicated, but is occupied by access to staticobjects.
Pre-store the reference of dict
VaR T = application. staticobjects ("dict ");
For (VAR I = 0; I <15000; I ++ ){
Application. Lock ();
T. Item ("O") [I] = "sdfdsffdsaf ";
Application. Unlock ();}
3094 ms, successfully reduced the time by more than half. What if the pre-storage policy that has been tested and tested in JS is to pre-store T. Item ("O?
VaR T = application. staticobjects ("dict"). Item ("O ");
For (VAR I = 0; I <15000; I ++ ){
Application. Lock ();
T [I] = "sdfdsffdsaf ";
Application. Unlock ();}
125 Ms, finally succeeded, only half of application. contents. It seems that the time is mainly spent on obtaining 'quota', rather than being protected slowly in the staticobjects memory zone. Compared with contents, staticobjects provides better security measures because objects need to be stored.
Relying on the powerful functions of dictionary, We can encapsulate it as appropriate. Using put (), get (), contains () and other popular methods for access is a powerful cache.
/// Remarks
I have encapsulated a. SCT component, written in ASP JavaScript, and sent it up when I have time. Today it is here.
The speed at which contens and staticobjects are referenced is tested. The speed is 0 ms for 20 times, and the speed of 100 times is about 5 times. The speed difference between and times is 10 times. However, access after retrieval is not affected.