cache.py 890 B

123456789101112131415161718192021222324252627282930
  1. # -*- coding: utf-8 -*-
  2. r"""按时间窗缓存与作业状态接口(**组件接入点:Redis**)。
  3. 现在:进程内 `_WIN_CACHE`(按时间窗重算结果)+ `run/ops_job.json`(作业状态)。
  4. 目标:同一接口下新增 Redis 实现,支持多实例共享缓存与分布式锁。
  5. P0 只立契约,无实现(默认仍是进程内 + 本地文件)。
  6. """
  7. from __future__ import annotations
  8. from abc import ABC, abstractmethod
  9. class WindowCache(ABC):
  10. @abstractmethod
  11. def get(self, kind: str, window_key: str): ...
  12. @abstractmethod
  13. def put(self, kind: str, window_key: str, value) -> None: ...
  14. @abstractmethod
  15. def pending(self, kind: str, window_key: str) -> bool: ...
  16. class JobState(ABC):
  17. @abstractmethod
  18. def read(self) -> dict: ...
  19. @abstractmethod
  20. def write(self, state: dict) -> None: ...