stock-ai-agent/clear_cache.py
2026-02-03 16:42:26 +08:00

48 lines
1.3 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
"""
清除缓存脚本
用于清除旧的K线数据缓存确保使用新的180天数据
"""
import sys
from pathlib import Path
# 添加项目路径
sys.path.insert(0, str(Path(__file__).parent / 'backend'))
from app.services.cache_service import cache_service
def main():
print("=" * 60)
print("清除K线数据缓存")
print("=" * 60)
try:
# 方案1清除K线相关缓存
kline_count = cache_service.clear_pattern("kline:")
print(f"\n✓ 清除K线缓存: {kline_count}")
# 方案2清除所有缓存可选
print("\n是否清除所有缓存?(y/n): ", end="")
choice = input().strip().lower()
if choice == 'y':
total_count = cache_service.clear_all()
print(f"✓ 清除所有缓存: {total_count}")
print("\n说明:")
print("- 已清除K线数据缓存")
print("- 下次查询时将使用新的180天数据范围")
print("- 技术指标将基于更完整的历史数据计算")
print("\n建议:重启应用以确保生效")
print(" pm2 restart stock-agent")
except Exception as e:
print(f"\n✗ 清除缓存失败: {e}")
import traceback
print(traceback.format_exc())
print("\n" + "=" * 60)
if __name__ == "__main__":
main()