enhance swap check
This commit is contained in:
parent
1a345ff726
commit
e9b8fd28b1
@ -173,22 +173,29 @@ class FileCacheOutputStream(BaseOutputStream):
|
|||||||
|
|
||||||
def check_flush(self) -> Path:
|
def check_flush(self) -> Path:
|
||||||
current_file = self.get_file_path()
|
current_file = self.get_file_path()
|
||||||
if self.file_swap:
|
# 获取当前文件的路径
|
||||||
size_pass = True
|
if not self.file_swap:
|
||||||
if self.file_size_limit > 0:
|
# 不需要 swap 直接返回
|
||||||
file_size = current_file.stat().st_size / 1024 # kb
|
return current_file
|
||||||
if file_size > self.file_size_limit: # kb
|
# 检查是否需要 swap
|
||||||
size_pass = False
|
size_pass = True
|
||||||
time_pass = True
|
if self.file_size_limit > 0:
|
||||||
if self.file_time_limit > 0:
|
file_size = current_file.stat().st_size / 1024 # kb
|
||||||
file_time = round(time.time()) - current_file.stat().st_mtime
|
if file_size > self.file_size_limit: # kb
|
||||||
if file_time > self.file_time_limit:
|
size_pass = False
|
||||||
time_pass = False
|
time_pass = True
|
||||||
if self.file_swap_on_both:
|
if self.file_time_limit > 0:
|
||||||
if size_pass and time_pass:
|
file_time = round(time.time()) - current_file.stat().st_mtime
|
||||||
self.file_swap_counter += 1
|
if file_time > self.file_time_limit:
|
||||||
# 生成新的文件名
|
time_pass = False
|
||||||
return current_file
|
if (self.file_swap_on_both and size_pass and time_pass) or \
|
||||||
|
(not self.file_swap_on_both and (size_pass or time_pass)):
|
||||||
|
# 两个都满足
|
||||||
|
# 或者只有一个满足
|
||||||
|
if size_pass and time_pass:
|
||||||
|
self.file_swap_counter += 1
|
||||||
|
# 生成新的文件名
|
||||||
|
return self.get_file_path()
|
||||||
|
|
||||||
def flush(self) -> None:
|
def flush(self) -> None:
|
||||||
new_cache = io.StringIO() # 创建新的缓存
|
new_cache = io.StringIO() # 创建新的缓存
|
||||||
|
Loading…
Reference in New Issue
Block a user