Apache Caching wxjs

8 views
Skip to first unread message

whoiste...@hotmail.com

unread,
Aug 30, 2007, 10:08:47 AM8/30/07
to wxJavaScript
I have a wxjs which I want to run each time it is requested.

Somehow the response is cached. I tried using mod_expires and
mod_header to influenue the Cache-control header (max_age=0) but
Firefox is still loading the cached data and not loading the updated
date?

How to avoid this? How to setup the cache mechanism properly?

Franky Braem

unread,
Aug 30, 2007, 12:39:22 PM8/30/07
to wxjava...@googlegroups.com
wxJS doesn't cache anything. The only way you can cache some values is
by adding properties to the 'wxjs' global object. The next release will
have a memcached client.
I suppose it is an Apache thing.

Franky.

whoiste...@hotmail.com

unread,
Aug 31, 2007, 7:53:02 AM8/31/07
to wxJavaScript
I think you're right, but I not sure what it is in Apache I need to
set properly?

This is what I have now, which doesn't work. The server keeps sending
the cached data? I do have SSL running, but I don't think that's the
cause of the problem.

Did you have the set the MIME type for wxjs?

<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Satisfy all
# ExpiresActive On
# ExpiresDefault A5
<FilesMatch "\.wxjs$">
Header set Cache-Control "no-cache, no-store"
Header set Expires "0"
Header set Pragma "no-cache"
</FilesMatch>
</Directory

On Aug 31, 12:39 am, Franky Braem <franky.br...@gmail.com> wrote:

whoiste...@hotmail.com

unread,
Sep 3, 2007, 9:12:35 AM9/3/07
to wxJavaScript
I did some experimentations and I changed some data in the wxjs code
and it's immediately reflected in the response, so it seems the
response is not cached.

However I am also using wxjs_DB and when I update my database, the
data is not reflected in the response. Seems mod_wxjs+wxjs_DB is
caching my query results.

So I tried to run the same code using command line wxjs and the data
is updated?

Any ideas? How mod_wxjs+wxjs_DB is caching the query results? Maybe
when the sql connection is opened and not closed, the same SQL
statements return cached results?

According to wxDB/main.cpp, the connection is only close when:

case DLL_PROCESS_DETACH:
wxDbCloseConnections();
break;
}

Not sure if DLL_PROCESS_DETACH occurs with mod_wxjs+wxjs_DB running
on Apache?

Franky Braem

unread,
Sep 3, 2007, 2:44:00 PM9/3/07
to wxjava...@googlegroups.com
whoiste...@hotmail.com wrote:
> I did some experimentations and I changed some data in the wxjs code
> and it's immediately reflected in the response, so it seems the
> response is not cached.
>
> However I am also using wxjs_DB and when I update my database, the
> data is not reflected in the response. Seems mod_wxjs+wxjs_DB is
> caching my query results.
>
> So I tried to run the same code using command line wxjs and the data
> is updated?
>
> Any ideas? How mod_wxjs+wxjs_DB is caching the query results? Maybe
> when the sql connection is opened and not closed, the same SQL
> statements return cached results?
>
> According to wxDB/main.cpp, the connection is only close when:
>
> case DLL_PROCESS_DETACH:
> wxDbCloseConnections();
> break;
> }
>
> Not sure if DLL_PROCESS_DETACH occurs with mod_wxjs+wxjs_DB running
> on Apache?
>
>
Can you try to use commitTrans:
http://www.wxjavascript.net/db/classes/wxDb.html#commitTrans ?
A script is run in it's own context and when that is cleaned up (after
each script has run), the destructor of wxDb is called.
The database is closed there.

Franky.

whoiste...@hotmail.com

unread,
Sep 3, 2007, 11:41:08 PM9/3/07
to wxJavaScript
I thought commitTrans might have a chance to fix this, since I am
query the database with a direct SQL command, but commitTrans did not
fix it. I am curious if it's is normal to close the ODBC connection
to avoid caching?

On Sep 4, 2:44 am, Franky Braem <franky.br...@gmail.com> wrote:

whoiste...@hotmail.com

unread,
Sep 3, 2007, 11:57:29 PM9/3/07
to wxJavaScript
Looks like Foxpro ODBC problem:
http://support.microsoft.com/kb/261267

It caches the result unless the connection is closed. Is there other
ways to close the connection?

franky...@gmail.com

unread,
Sep 4, 2007, 2:57:17 AM9/4/07
to wxJavaScript

On 4 sep, 05:57, whoisterence...@hotmail.com wrote:
> Looks like Foxpro ODBC problem:http://support.microsoft.com/kb/261267
>
> It caches the result unless the connection is closed. Is there other
> ways to close the connection?
>

I will re-add the close method. I removed it, because it can create
problems when you still use db-related classes while the database is
closed.

Franky.

whoiste...@hotmail.com

unread,
Sep 5, 2007, 7:07:24 AM9/5/07
to wxJavaScript
Frank,

I tried adding the wxDbCloseConnections(); to a newly created
wxdb.close(), but looks like the problem is not solved. Not sure if I
added this function into db.h and db.cpp correctly? But the module
loads with mod_wxjs and I can pull the date online, but the data is
still not updated as previously mentioned.

I hope once I can close the odbc connection this problem would go
away, but at the sametime, I am wondernig if something else is
happening offline with wxjs+wxdb which doesn't happen with mod_wxjs
+wxdb? Any ideas?

Regards
Terence

Franky Braem

unread,
Sep 5, 2007, 4:21:01 PM9/5/07
to wxjava...@googlegroups.com
whoiste...@hotmail.com wrote:
> Frank,
>
> I tried adding the wxDbCloseConnections(); to a newly created
> wxdb.close(), but looks like the problem is not solved. Not sure if I
> added this function into db.h and db.cpp correctly? But the module
> loads with mod_wxjs and I can pull the date online, but the data is
> still not updated as previously mentioned.
>
> I hope once I can close the odbc connection this problem would go
> away, but at the sametime, I am wondernig if something else is
> happening offline with wxjs+wxdb which doesn't happen with mod_wxjs
> +wxdb? Any ideas?
>
> Regards
> Terence
>
I have written the close method as follows:

JSBool Database::close(JSContext *cx,
JSObject *obj,
uintN WXUNUSED(argc),
jsval* WXUNUSED(argv),
jsval* WXUNUSED(rval))
{
Database *p = GetPrivate(cx, obj);
if ( p == NULL )
return JS_FALSE;
wxDb *db = ((DatabaseRefData *)p->GetRefData())->GetDB();

db->Close();

return JS_TRUE;
}

The difference between mod_wxjs and wxjs shell is that the shell process
immediately ends and cleans up the js runtime.
This is not the case in mod_wxjs, because the apache process is kept
alive. But all the classes and variables created in a server-side script
are created on a global object that is new for every script execution.
So the wxDb should be closed when the context is destroyed. Is your
database stored in a variable declared with the var-keyword? Because
there is a subtle life-time difference when you don't use the 'var' keyword.

Franky.

whoiste...@hotmail.com

unread,
Sep 10, 2007, 1:27:34 PM9/10/07
to wxJavaScript
Frank,

I tried db->Close(), but it crashes wxjs.exe. wxDbCloseConnections
doesn't crash, but it query data is still being cached.

All my variables have var-keyword. And I even try to put the entire
code into a function so all var-keyword variables should be local.

And ideas? I understand some things are destroyed when script ends in
wxjs shell. How can I go about debugging this?

On Sep 6, 4:21 am, Franky Braem <franky.br...@gmail.com> wrote:

Franky Braem

unread,
Sep 10, 2007, 1:46:33 PM9/10/07
to wxjava...@googlegroups.com
whoiste...@hotmail.com wrote:
> Frank,
>
> I tried db->Close(), but it crashes wxjs.exe. wxDbCloseConnections
> doesn't crash, but it query data is still being cached.
>
>
This is what the assert tells us:

19:34:23: Debug: ..\..\src\common\db.cpp(1749): assert "nTables == 0"
failed in
wxDb::Close().

The problem is there are still tables open when close is called. This
doesn't happen when the script ends (without calling close), because the
close will only be called when all tables are destructed. A table holds
a reference to a database, and releases it when it is destructed.

This is what the wxWidgets manual says: Any wxDbTable instances which
use this connection must be deleted before closing the database
connection. Now in JavaScript you don't have control of the destruction
of objects. So the close method is no solution for this problem.

I will try to debug more and see if the database is closed when the
script is ended in Apache.

Franky.

whoiste...@hotmail.com

unread,
Sep 11, 2007, 8:27:37 AM9/11/07
to wxJavaScript
Frank,

I used ODBC Tracer log to check whether there is a difference between
mod_wxjs and wxjs shell ODBC Calls to the database, they are the same
except one thing mod_wxjs doesn't seem to repeat the calls when I
request the script, this prove the bug about closing connection is
correct. Also, the log file is locked until I kill apache, I think
it's very clear something between wxDB and the ODBC is caching the
result or not openning a new connection.

I think you're in the right direction, first delete the table and then
close the connection.

On Sep 11, 1:46 am, Franky Braem <franky.br...@gmail.com> wrote:

whoiste...@hotmail.com

unread,
Sep 11, 2007, 8:50:27 AM9/11/07
to wxJavaScript
I tried to add close to dbtable as follows:

JSBool Table::close(JSContext *cx, JSObject *obj, uintN argc, jsval
*argv, jsval *rval)
{
Table *p = Table::GetPrivate(cx, obj);


if ( p == NULL )
return JS_FALSE;

delete p->m_table;
return JS_TRUE;
}

This crashes wxjs shell. Not sure how to delete wxDbTable ? :)

Franky Braem

unread,
Sep 11, 2007, 2:36:29 PM9/11/07
to wxjava...@googlegroups.com
whoiste...@hotmail.com wrote:
> I tried to add close to dbtable as follows:
>
> JSBool Table::close(JSContext *cx, JSObject *obj, uintN argc, jsval
> *argv, jsval *rval)
> {
> Table *p = Table::GetPrivate(cx, obj);
> if ( p == NULL )
> return JS_FALSE;
>
> delete p->m_table;
> return JS_TRUE;
> }
>
> This crashes wxjs shell. Not sure how to delete wxDbTable ? :)
>
Two corrections: you must delete p instead of p->table and you must set
the private data of object to NULL, because the JS destructor will try
to delete the table also.
So do this:

JSBool Table::close(JSContext *cx, JSObject *obj, uintN argc, jsval
*argv, jsval *rval)
{
Table *p = Table::GetPrivate(cx, obj);
if ( p == NULL )
return JS_FALSE;

delete p;
JS_SetPrivate(cx, obj, NULL);
return JS_TRUE;
}

Now we have to check p in every function, because this will crash the
shell also.

Franky.

whoiste...@hotmail.com

unread,
Sep 12, 2007, 3:25:00 AM9/12/07
to wxJavaScript
Dear Frank,

That did the trick, now the wxDB is returning updated data. Thanks.

Regards
Terence

On Sep 12, 2:36 am, Franky Braem <franky.br...@gmail.com> wrote:

Reply all
Reply to author
Forward
0 new messages