[ZODB-Dev] cache gc api

Andrew Kuchling akuchlin@mems-exchange.org
Fri, 2 Nov 2001 12:47:25 -0500


On Fri, Nov 02, 2001 at 12:04:13PM -0500, Jeremy Hylton wrote:
>It's relying on some internal implementation details -- specifically
>that it divides the times it uses by 3 and then takes % 65356.  So it
>you specifiy an age greater than 3 * 65536, then you've effectively
>specified an age older than all objects.

The code in cPickleCache.c for doing all this is pretty confusing.
The current time is taken, divided by 3, and then taken % 65536:

ute ZODB>egrep '/\s*3' *.c *.h
cPersistence.c:         self->atime=((long)(time(NULL)/3))%65536;
cPersistence.c:      self->atime=((long)(time(NULL)/3))%65536;
cPersistence.c:      self->atime=((long)(time(NULL)/3))%65536;
cPickleCache.c:  now=((long)(time(NULL)/3))%65536;
cPickleCache.c:  now=((long)(time(NULL)/3))%65536;
cPickleCache.c:  now=((long)(time(NULL)/3))%65536;
cPersistence.h:#define PER_ACCESSED(O) ((O)->atime=((long)(time(NULL)/3))%65536)
ute ZODB>

(The PER_ACCESSED macro doesn't seem to be actually used; it probably
should be.)  

All this math seems to be done so that the access time in the
cPersistence struct can be a 16-bit short.  Is the savings of 2 bytes
per persistent item worth all this pain and confusion? 

--amk