[Zope] Persisting data in a module for hit counter

Max M maxm at mxm.dk
Wed Feb 25 09:43:50 EST 2004


I have a dictionary that I want to share between request, but I do not 
want it to be persistent in the zodb.

Rather I want to pickle it and store it on the filesystem.

Getting the pickled data is easy enough, as I only need to read the 
pickled file at the module level.

The problem is when zope is stopped, or a module is reloaded, then it 
looses all data.

Is there any way to know when a module goes out of scope, so that I can 
get a hook to save/pickle the dictionary? Or at least a way to know when 
zope is shut down?


My alternative option is to set a counter that saves the data after n 
number of write to the dictionary. This can work, as it is not critical 
data anyway.

--------------------

It's a simple hit counter/stat module, that stores counts as:

counters = {
     urlpath:count,
}

It has the advantage over FScounter in that it only needs one instance 
to work for all pages in a site.

Ie. if you put this code into the footer of a Plone site, you will get a 
counter on all pages.:

This page has been visited:
<span tal:content="python:here.mxm_counter.count(here)"/>
times.

Also you can have a nice statistics page with a list of visited pages.

It works nicely allready, but only between restarts :-)



regards Max M



More information about the Zope mailing list