url preview: Use in-memory caching in dev environment.

This commit is contained in:
Puneeth Chaganti 2019-05-02 20:44:08 +05:30 committed by Tim Abbott
parent 1f6306a5a7
commit da33b72848
3 changed files with 13 additions and 2 deletions

View File

@ -1,6 +1,7 @@
import re
import requests
from django.conf import settings
from django.utils.encoding import smart_text
from typing import Any, Optional, Dict
from typing.re import Match
@ -10,7 +11,10 @@ from zerver.lib.url_preview.oembed import get_oembed_data
from zerver.lib.url_preview.parsers import OpenGraphParser, GenericParser
CACHE_NAME = "database"
# FIXME: Should we use a database cache or a memcached in production? What if
# opengraph data is changed for a site?
# Use an in-memory cache for development, to make it easy to develop this code
CACHE_NAME = "database" if not settings.DEVELOPMENT else "in-memory"
# Based on django.core.validators.URLValidator, with ftp support removed.
link_regex = re.compile(
r'^(?:http)s?://' # http:// or https://

View File

@ -27,7 +27,11 @@ TEST_CACHES = {
'database': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
'LOCATION': 'url-preview',
}
},
'in-memory': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
'LOCATION': 'url-preview',
},
}
@override_settings(INLINE_URL_EMBED_PREVIEW=True)

View File

@ -682,6 +682,9 @@ CACHES = {
'CULL_FREQUENCY': 10,
}
},
'in-memory': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
},
}
########################################################################