/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/knit.py

  • Committer: John Arbash Meinel
  • Date: 2006-07-24 20:05:07 UTC
  • mto: This revision was merged to the branch mainline in revision 1885.
  • Revision ID: john@arbash-meinel.com-20060724200507-6a9b467053048ace
Removing disk-backed-cache

Show diffs side-by-side

added added

removed removed

Lines of Context:
73
73
import sys
74
74
import warnings
75
75
 
76
 
from bzrlib import disk_backed_cache
77
76
import bzrlib
78
77
import bzrlib.errors as errors
79
78
from bzrlib.errors import FileExists, NoSuchFile, KnitError, \
1290
1289
 
1291
1290
    HEADER = "# bzr knit data 8\n"
1292
1291
 
1293
 
    # If caching is enabled, don't let it grow larger than this
1294
 
    # in memory (before writing to disk)
1295
 
    _max_memory_cache_size = 10*1024*1024
1296
 
 
1297
1292
    def __init__(self, transport, filename, mode, create=False, file_mode=None):
1298
1293
        _KnitComponentFile.__init__(self, transport, filename, mode)
1299
1294
        self._checked = False
1300
 
 
1301
 
        # This starts off as a plain dict, because if we aren't caching
1302
 
        # we don't want any overhead for lookups
 
1295
        # TODO: jam 20060713 conceptually, this could spill to disk
 
1296
        #       if the cached size gets larger than a certain amount
 
1297
        #       but it complicates the model a bit, so for now just use
 
1298
        #       a simple dictionary
1303
1299
        self._cache = {}
1304
1300
        self._do_cache = False
1305
1301
        if create:
1307
1303
 
1308
1304
    def enable_cache(self):
1309
1305
        """Enable caching of reads."""
1310
 
        if not self._do_cache:
1311
 
            self._do_cache = True
1312
 
            self._cache = disk_backed_cache.DiskBackedCache(
1313
 
                            # Cache things in RAM. Only spill to disk if the 
1314
 
                            # Transport says we should cache (all remote 
1315
 
                            # transports return True, local transports 
1316
 
                            # return False)
1317
 
                            use_disk=self._transport.should_cache(),
1318
 
                            # If the same entry is added twice, we have a
1319
 
                            # bug somewhere
1320
 
                            allow_replace=False,
1321
 
                            # TODO: This is a policy bit. If we cross the
1322
 
                            #       threshold, do we dump everything to disk,
1323
 
                            #       or do we just dump new stuff
1324
 
                            flush_all=False,
1325
 
                            max_size=self._max_memory_cache_size
1326
 
                            )
 
1306
        self._do_cache = True
1327
1307
 
1328
1308
    def clear_cache(self):
1329
1309
        """Clear the record cache."""
1330
1310
        self._do_cache = False
1331
 
        # Caching is now disabled, so switch back to a plain dict
1332
 
        self._cache.clear()
1333
1311
        self._cache = {}
1334
1312
 
1335
1313
    def _open_file(self):