yxy添加 clear_cache.py 注释

yxy_branch
严欣怡 6 months ago
parent 3152a41bd2
commit 34b683c86a

@ -1,11 +1,26 @@
# 导入Django命令基类用于创建自定义管理命令
from django.core.management.base import BaseCommand
# 导入项目自定义的缓存工具封装自djangoblog.utils
from djangoblog.utils import cache
class Command(BaseCommand):
"""
Django自定义管理命令清除系统所有缓存
用于手动触发缓存清理确保缓存数据与数据库同步
"""
# 命令的帮助信息执行python manage.py help clear_cache时显示
help = 'clear the whole cache'
def handle(self, *args, **options):
"""
命令核心执行逻辑
当运行python manage.py clear_cache时调用
"""
# 调用缓存工具的clear()方法,清除所有缓存数据
# 这里的cache是项目自定义的缓存实例可能封装了Django原生缓存或其他缓存后端
cache.clear()
self.stdout.write(self.style.SUCCESS('Cleared cache\n'))
# 向控制台输出成功信息使用Django命令的样式工具显示绿色成功提示
self.stdout.write(self.style.SUCCESS('Cleared cache\n'))
Loading…
Cancel
Save