Skip to content

cache — Local cache

CSV cache with incremental refresh: full fetch on first run, then only draws newer than the latest cached date.

cache

Attributes

DEFAULT_CACHE_DIR module-attribute

DEFAULT_CACHE_DIR = Path.home() / '.lotterycn' / 'history'

Functions:

get_cache_path

get_cache_path(lottery_name: str, cache_dir: Optional[str] = None, table: str = 'history') -> Path

计算某彩种某表的缓存 CSV 路径,并确保缓存目录存在。

Parameters:

Name Type Description Default
lottery_name str

str, 彩种代码。

required
cache_dir Optional[str]

str, optional, 缓存目录;None 时取环境变量或默认值(见 get_cache_path)。

None
table str

str, 数据表名(如 history / detail / prizes / provinces)。

'history'

Returns:

Type Description
Path

pathlib.Path, 缓存文件路径 lotterycn_{table}_{lottery_name}.csv。

load_cached_history_data

load_cached_history_data(lottery_name: str, cache_dir: Optional[str] = None, **kwargs) -> Union[list, DataFrame]

带本地缓存的历史开奖数据加载。

首次调用全量拉取并写入 CSV;之后读取本地缓存,仅拉取最后开奖日期之后的数据并合并去重。 is_detail_result=True 的明细结果不落盘,直接透传。

Parameters:

Name Type Description Default
lottery_name str

str, 彩种代码。

required
cache_dir Optional[str]

str, optional, 缓存目录;None 时取环境变量或默认值(见 get_cache_path)。

None
**kwargs

透传给 load_history_data(如 is_detail_result、timeout);if_cached 由本层 消费后立即剥离,防止 data 层再次分发回本层造成无限递归;命中缓存时 begin_date 会被 改写为增量起点(福彩系)。

{}

Returns:

Type Description
Union[list, DataFrame]

Union[list, pandas.DataFrame], is_detail_result=True 时透传明细(list),否则返回 合并去重后的历史 DataFrame。