You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tentest/doc/DjangoBlog/blog/management/commands/clear_cache.py

33 lines
810 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

from django.core.management.base import BaseCommand
from djangoblog.utils import cache
class Command(BaseCommand):
"""
mk:
Django管理命令类用于清除整个缓存
该类继承自Django的BaseCommand提供了一个自定义的管理命令
可以通过命令行调用来清除应用的所有缓存数据
"""
help = 'clear the whole cache'
def handle(self, *args, **options):
"""
mk:
处理管理命令的主要逻辑
参数:
*args: 位置参数元组
**options: 关键字参数字典
返回值:
None
"""
# mk:清除所有缓存数据
cache.clear()
# mk:输出成功信息到标准输出
self.stdout.write(self.style.SUCCESS('Cleared cache\n'))