diff --git a/zerver/lib/url_preview/preview.py b/zerver/lib/url_preview/preview.py index 0dc5cdaae0..31577b2a3e 100644 --- a/zerver/lib/url_preview/preview.py +++ b/zerver/lib/url_preview/preview.py @@ -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:// diff --git a/zerver/tests/test_link_embed.py b/zerver/tests/test_link_embed.py index ff6e0a221d..abebc137e2 100644 --- a/zerver/tests/test_link_embed.py +++ b/zerver/tests/test_link_embed.py @@ -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) diff --git a/zproject/settings.py b/zproject/settings.py index adc101b4ce..68fc8b59fd 100644 --- a/zproject/settings.py +++ b/zproject/settings.py @@ -682,6 +682,9 @@ CACHES = { 'CULL_FREQUENCY': 10, } }, + 'in-memory': { + 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache', + }, } ########################################################################