X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=bup.git;a=blobdiff_plain;f=lib%2Fbup%2Fvfs.py;h=0ac31a99d103afd0cefa91359819ae24c711ed6a;hp=14293dc202e8fb50172d8e1f03a9e29ecabcfba8;hb=8c3db8e73da813181213b71eff278fd0122c9b42;hpb=40642ff27e4c9860d34c713b4388ee98d62b2f52 diff --git a/lib/bup/vfs.py b/lib/bup/vfs.py index 14293dc..0ac31a9 100644 --- a/lib/bup/vfs.py +++ b/lib/bup/vfs.py @@ -49,6 +49,7 @@ from __future__ import absolute_import, print_function from collections import namedtuple from errno import ELOOP, ENOENT, ENOTDIR from itertools import chain, dropwhile, groupby, izip, tee +from random import randrange from stat import S_IFDIR, S_IFLNK, S_IFREG, S_ISDIR, S_ISLNK, S_ISREG from time import localtime, strftime import exceptions, re, sys @@ -273,13 +274,15 @@ def cache_notice(key, value): assert is_valid_cache_key(key) if key in _cache: return - _cache[key] = value if len(_cache) < _cache_max_items: + _cache_keys.append(key) + _cache[key] = value return - victim_i = random.randrange(0, len(_cache_keys)) + victim_i = randrange(0, len(_cache_keys)) victim = _cache_keys[victim_i] + del _cache[victim] _cache_keys[victim_i] = key - _cache.pop(victim) + _cache[key] = value def cache_get_commit_item(oid, need_meta=True):