Version française
Home     About     Download     Resources     Contact us    
Browse thread
environment idiom
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jacques Garrigue <garrigue@m...>
Subject: Re: [Caml-list] environment idiom
From: Richard Jones <rich@annexia.org>

> The specific data that Jeff wants to pass around are:
> 
> cgi    - The CGI environment
> r      - The Apache request_rec (in fact, cgi#request == request,
>          but sometimes it's slightly more convenient to have it as
>          a separate parameter)
> dbh    - The database handle
> hostid - The host ID (COCANWIKI supports multiple virtual hosts)
> host   - The "host object" which contains other host-related info
> user   - The "user object" which contains info on the logged-in user
> 
> In theory one can derive all of the above from just cgi and dbh, but
> it's very inefficient to do this because it would require making
> database requests.  For practical and efficiency reasons COCANWIKI
> derives the hostid, host and user with just 2 database queries at the
> beginning of every HTTP request.

But you could also make an object with all the methods, and caching
the information it retrieves from the database. This way you have no
efficiency problem.
Andrej's point was that it is generally enough to collect all common
information in one object, and you have not so much to move around
after that. I think this is reasonable.
If this is not the case, then it may mean that you really need to add
information dynamically to your environment. In that case an approach
like the one I suggested with records might provide more flexibility.

Jacques Garrigue