cache_cleanup.py 664 B

12345678910111213141516171819202122232425
  1. # -*- coding: utf-8 -*-
  2. """
  3. Daily cleanup job.
  4. Can be run as a cronjob to clean out old data from the database (only expired
  5. sessions at the moment).
  6. """
  7. import six
  8. from django.conf import settings
  9. from django.core.cache import caches
  10. from django_extensions.management.jobs import DailyJob
  11. class Job(DailyJob):
  12. help = "Cache (db) cleanup Job"
  13. def execute(self):
  14. if hasattr(settings, 'CACHES'):
  15. for cache_name, cache_options in six.iteritems(settings.CACHES):
  16. if cache_options['BACKEND'].endswith("DatabaseCache"):
  17. cache = caches[cache_name]
  18. cache.clear()
  19. return