Django Cache
settings.py
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 }, } }
Creating the cache table
Before using the database cache, you must create the cache table with this command:
python manage.py createcachetable
cache page
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"),
출처
관련 문서
Plugin Backlinks: 아무 것도 없습니다.