Skip to content

Commit

Permalink
Force storage cleaning if cleaning from command line
Browse files Browse the repository at this point in the history
  • Loading branch information
9a4gl committed Feb 8, 2019
1 parent d03ff7d commit 030993b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
16 changes: 8 additions & 8 deletions clcache/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,9 +636,9 @@ def setManifest(self, manifestHash, manifest):
def getManifest(self, manifestHash):
return self.manifestRepository.section(manifestHash).getManifest(manifestHash)

def clean(self, stats, maximumSize, cleanFactor):
def clean(self, stats, maximumSize, cleanFactor, force):
currentSize = stats.currentCacheSize()
if currentSize < maximumSize:
if not force and currentSize < maximumSize:
return

# Free at least 10% to avoid cleaning up too often which
Expand Down Expand Up @@ -689,8 +689,8 @@ def configuration(self):
def statistics(self):
return self.strategy.statistics

def clean(self, stats, maximumSize, cleanFactor):
return self.strategy.clean(stats, maximumSize, cleanFactor)
def clean(self, stats, maximumSize, cleanFactor, force):
return self.strategy.clean(stats, maximumSize, cleanFactor, force)

@contextlib.contextmanager
def lockFor(self, key):
Expand Down Expand Up @@ -1512,9 +1512,9 @@ def resetStatistics(cache):
stats.resetCounters()


def cleanCache(cache, cleanFactor = 0.9):
def cleanCache(cache, cleanFactor = 0.9, force = False):
with cache.lock, cache.statistics as stats, cache.configuration as cfg:
cache.clean(stats, cfg.maximumCacheSize(), cleanFactor)
cache.clean(stats, cfg.maximumCacheSize(), cleanFactor, force)


def clearCache(cache):
Expand Down Expand Up @@ -1628,12 +1628,12 @@ def main():
return 0

if len(sys.argv) == 2 and sys.argv[1] == "-c":
cleanCache(cache)
cleanCache(cache, force=True)
print('Cache cleaned')
return 0

if len(sys.argv) == 3 and sys.argv[1] == "-c":
cleanCache(cache, float(sys.argv[2]))
cleanCache(cache, float(sys.argv[2]), True)
print('Cache cleaned')
return 0

Expand Down
10 changes: 6 additions & 4 deletions clcache/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,11 @@ def _setIgnoreExc(self, key, value):
def getManifest(self, manifestHash):
return self.client.get((self.manifestPrefix + manifestHash).encode("UTF-8"))

def clean(self, stats, maximumSize, cleanFactor):
def clean(self, stats, maximumSize, cleanFactor, force):
self.fileStrategy.clean(stats,
maximumSize,
cleanFactor)
cleanFactor,
force)


class CacheFileWithMemcacheFallbackStrategy:
Expand Down Expand Up @@ -225,7 +226,8 @@ def lock(self):
with self.remoteCache.lock, self.localCache.lock:
yield

def clean(self, stats, maximumSize, cleanFactor):
def clean(self, stats, maximumSize, cleanFactor, force):
self.localCache.clean(stats,
maximumSize,
cleanFactor)
cleanFactor,
force)

0 comments on commit 030993b

Please sign in to comment.