StyleEdit / pipeline /archive_cache.py
faraway00's picture
Refresh verified six-GPU manifest: 26 tuples
99dca31 verified
Raw History Blame Contribute Delete
637 Bytes
"""Root-disk, immutable range cache; only atomic completed chunks are readable."""
import os
from pathlib import Path
ROOT=Path('/opt/styleedit-archive-cache')
BLOCK=64*1024**2
def cached_range(category,start,length):
chunks=[]; pos=start; end=start+length
while pos<end:
base=pos//BLOCK*BLOCK
path=ROOT/category/f'{base:012d}.chunk'
try:
with path.open('rb') as f:
f.seek(pos-base); n=min(end-pos,BLOCK-(pos-base)); data=f.read(n)
except FileNotFoundError:return None
if len(data)!=n:return None
chunks.append(data);pos+=n
return b''.join(chunks)