Message30189
Logged In: YES
user_id=341410
Add a deque and a bit of logic, and one would get a fifo
implementation of the cache.
from collections import deque
_toss = deque()
def _compile(fmt):
# Internal: compile struct pattern
if len(_cache) >= _MAXCACHE:
del _cache[_toss.popleft()]
s = Struct(fmt)
_cache[fmt] = s
_toss.append(fmt)
return s
Race conditions from multiple threads could result in
#threads-1 more entries in the cache than _MAXCACHE, but
this could be trimmed in later calls by replacing 'if' with
'while'. |
|
Date |
User |
Action |
Args |
2007-08-23 14:43:37 | admin | link | issue1573394 messages |
2007-08-23 14:43:37 | admin | create | |
|