0

I use G-WAN to develop a website and I would like to count how much a page with a static URI has been called in order to display some statistics, but with the automatic caching system of G-WAN my counter is wrong sometimes. Is there a way to completely disable this cache. I have already developed a caching system with the KV store provided with G-WAN and with this way I can count and serve a cached page correctly so I really don't need the automatic caching system of G-WAN... If anyone has a solution to my problem I am interested.

Cheers Jérôme

user1606908
  • 89
  • 1
  • 5
  • If your goal is to COUNT URIs then use a G-WAN handler, this will trigger before any caching can take place. – Gil Apr 08 '13 at 17:01
  • that's exactly what I wanna do so instead of counting in my script located in the csp folder I will count using the handler. Thank you – user1606908 Apr 08 '13 at 18:20

3 Answers3

2

Here is example of what u can do (assuming You trace specific urls only):

case HDL_AFTER_PARSE:{
    data_t * pp = *(data_t**)get_env(argv,US_SERVER_DATA);
    char *qs=get_env(argv,QUERY_STRING);
    if(qs&&!strncmp(qs,"i_count_those",sizeof("i_count_those")-1)){ 
        ++pp->count;
    }
} break;
//this is obviously code for handler
Linus Caldwell
  • 10,908
  • 12
  • 46
  • 58
deepinit
  • 66
  • 3
  • thank you for the example. In fact I count every request, not only specific URL. If I count using a handler do you mean the micro caching mechanism will not be applied before? – user1606908 Apr 07 '13 at 22:03
  • "I count using a handler do you mean the micro caching mechanism will not be applied before?". Yes ucache would not work. But if u count *ALL* requests just do --> get_env(argv,CC_HTTP_REQ); – deepinit Apr 07 '13 at 23:56
  • CC_HTTP_REQ give the global counter for all requests but I wanna count for each URI. But adding a random parameter like client_IP_dateTime or counting using a handler can be the solution – user1606908 Apr 08 '13 at 08:16
  • Whay not accept deepinit's answer? That's the correct answer. – Gil Apr 08 '13 at 17:14
0

I understand what you're asking, but the manual and previous answers the creator on this topic are quite clear.

Simply put, it's not possible to disable the micro-caching for a variety of reasons and the simple way around it is to add a query string or argument to each request:

?req/1

?req/a

You can ignore whatever you have automatically appended to the "query string" and still work off the same "page" or servlet for your statistics.

Mike
  • 94
  • 4
  • Thank you for the reply. I think I gonna use nginx which is already in frontend of g-wan to add a random parameter. – user1606908 Apr 07 '13 at 19:31
  • It would be nice to have the option to deactivate or active the auto caching mechanism, because in some cases it's more an issue than on optimization. – user1606908 Apr 08 '13 at 08:53
  • Caching is disabled by default and can only be enabled in the `gwan/init.c` file... – Gil Dec 11 '13 at 06:27
0

On the other hand, all calls are logged in the log folder of the host/virtual host. Or by using code as google analytics.

The question here is more why do you need those statistics? To show the user? - that's normally not a feature a user would require. I believe thar the user would be more interested in getting a fast answer from a micro cached GWAN server than a slow answer with statistical information from another server. Are the statistics for you? - Just use the GWAN server host /virtual host log.

If you really need to give special feedback to the user why not using the comet streaming to send that info as stated on http://gwan.ch/api#comet

Paulo Melo
  • 176
  • 1
  • 1
  • The statistics are for the user otherwise I would use google analytics. Parsing the log file could be a solution but I have already implemented the statistics module by counting the incoming queries. – user1606908 Apr 07 '13 at 19:32
  • To count URIs use a G-WAN handler, it is executed before caching can take place. – Gil Apr 08 '13 at 17:02