private void clearSizeForNewFile() {
		
		long fsSize = getFilesSumSize();
		long filesCount = files.size();
		
		Set<Integer> toRemoveFileNumbers = new HashSet<>();
		Set<FsCacheFile> toRemoveFiles = new HashSet<>();
		
		for (Map.Entry<Integer, FsCacheFile> entry : files.entrySet()) {
			
			if (fsSize + fsCacheFileMaxSize <= settings.getFsCacheMaxSize() && filesCount < settings.getFsCacheFilesCount()) {
				break;
			}
			
			FsCacheFile file = entry.getValue();
			toRemoveFileNumbers.add(entry.getKey());
			toRemoveFiles.add(file);
			fsSize -= file.getSize();
			filesCount--;
		}
		
		if (!toRemoveFiles.isEmpty()) {
			
			Iterator<Map.Entry<String, FsCachePosition>> pi = positions.entrySet().iterator();
			while (pi.hasNext()) {
				FsCacheFile file = pi.next().getValue().getFile();
				if (toRemoveFiles.contains(file)) {
					pi.remove();
				}
			}
			
			for (Integer fileNumber : toRemoveFileNumbers) {
				deleteFile(files.remove(fileNumber));
			}
		}
		
	}