Show pageOld revisionsBacklinksBack to top This page is read only. You can view the source, but not change it. Ask your administrator if you think this is wrong. # Django Cache {{tag>django cache}} - [[django cache clear]] ## settings.py <code> CACHE_HOURS = 12 ITEM_VALID_HOURS = 6 CACHES = { 'default': { 'BACKEND': 'django.core.cache.backends.db.DatabaseCache', 'LOCATION': 'my_cache', # 'TIMEOUT': 604800, # 7 days # 'TIMEOUT': 60 * 60 * 24, # 1 day 'TIMEOUT': 60 * 60 * CACHE_HOURS, # 12 hours 'OPTIONS': { 'MAX_ENTRIES': 5000000, # https://docs.djangoproject.com/en/1.11/topics/cache/#cache-arguments }, } } </code> ## Creating the cache table Before using the database cache, you must create the cache table with this command: <code> python manage.py createcachetable </code> ## cache page <code> from django.conf import settings from django.views.decorators.cache import cache_page cache = cache_page(60 * 60 * settings.CACHE_HOURS) path('image/similar', cache(ImageSimilarView.as_view()), name="image_similar"), </code> ## 출처 - https://docs.djangoproject.com/en/2.2/topics/cache/ open/django-cache.txt Last modified: 2024/10/05 06:15by 127.0.0.1