cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Oliver <res1c...@verizon.net>
Subject Re: [flow] session creation
Date Fri, 18 Jul 2003 04:55:20 GMT
Geoff Howard wrote:

> Thank you for this solution!  Can you explain to my poor pea brain the 
> difference between a global variable and a global constant in this 
> context?  IOW, if I want to use global "contants" how do I create and 
> access them in such a way as to avoid a session?
>
> Geoff


If you assign a global variable outside of a function but never assign 
it inside a function then no session will be created, as in your earlier 
example, reproduced here:

>
>
> So (can't test this now) does that mean that even currently, if 
> instead of:
>
> var role = Packages.org.apache.cocoon.caching.Cache.ROLE;
> function cacheEvent() { ...
>
> I do:
>
> function cacheEvent() {
> var role = Packages.org.apache.cocoon.caching.Cache.ROLE;
> ...
>
> I skip the session? 


As long as you don't assign to "role" inside a function, the session 
will be skipped in both cases..

This solution isn't perfect though. If you create a global object and 
modify its properties, those changes will not be preserved unless you 
create a session:

  1  var  myObj = new MyObject();
  2  myObj.prop = 3;
  3
  4   function page1() {
  5      myObj.prop = 1;
  6      sendPage("page1.html");
  7   }
  8
  9   function page2() {
10       print(myObj.prop); // prints 3 if no session, but 1 if  you 
have a session
11       sendPage("page2.html");
12   }

With no session, the assignments on lines 1-2 will be executed each time 
the script is called. If you have a session, they will only be executed 
the first time the script is called.

Chris







Mime
View raw message