views:

36

answers:

1

In classic ASP (which I am forced to use), I have a few factory functions, that is, functions that return classes. I use JScript.

In one include file I use these factory functions to create some classes that are used throughout the application. This include file is included with the #include directive in all pages.

These factory functions do some "heavy lifting" and I don't want them to be executed on every page load.

So, to make this clear I have something like this:

// factory.inc
function make_class(arg1, arg2) {
    function klass() {
         //...
    }

    // ... Some heavy stuff

    return klass;
}

// init.inc, included everywhere
<!-- #include FILE="factory.inc" -->
// ...
MyClass1 = make_class(myarg01, myarg02);
MyClass2 = make_class(myarg11, myarg12);
//...

How can I achieve the same effect without calling make_class on every page load? I know that

  • I can't cache the classes in the Application object
  • I can't use the Application_OnStart hook in Global.asa
  • I could probably create a scripting component, but I really don't want to do that

So, is there something else I can do? Maybe some way to achieve caching of these classes, which are really objects in JScript.

PS: [further clarification] In the above code "heavy stuff" is not so heavy, but I just want to know if there's a way to avoid it being executed all the time. It reads database meta information, builds a table of the primary keys in the database and another table that resolves strings to classes, etc.

A: 

it is not possible to store objects of asp classes in sessions or application (in VBScript).

that is because objects in ASP Classic are not serializable. well not automatically serializable. you could do it yourself.... but that means of course some extra work.

as i said above it is not possible to store classes written in vbscript in session or application.

you can stor classes written in jscript in the session or application. so what you have to do is write your classes in jscript in store them in the session.

then use thos classes from your (existing) vbscript code.

example:

<script runat="server" language="jscript"> function MyClass() { this.Var1 = "54321"; this.Var2 = Var2; } var Var1, Var2;

function MyClassFactory() { return new MyClass(); } </script> <script runat="server" language="vbscript">

dim instance : set instance = MyClassFactory() instance.Var1 = "12345"

set session("sesInstance") = instance

response.write session("sesInstance").Var1 </script>

hope that helps sorry for my incompetence in pasting the code correctly formatted...

ulluoink