frontend groundwork
This commit is contained in:
@@ -13,6 +13,6 @@ EXPOSE 8000
|
||||
# Set environment variables used by the deployment. These can be overridden by the user using this image.
|
||||
ENV NUM_WORKERS=1
|
||||
ENV OSM_CACHE_DIR=/cache
|
||||
ENV MEMCACHED_HOST=none
|
||||
ENV MEMCACHED_HOST_PATH=none
|
||||
|
||||
CMD fastapi run src/main.py --port 8000 --workers $NUM_WORKERS
|
||||
|
@@ -26,6 +26,6 @@ logging.config.dictConfig(config)
|
||||
if os.getenv('DEBUG', False):
|
||||
logging.getLogger().setLevel(logging.DEBUG)
|
||||
|
||||
MEMCACHE_HOST = os.getenv('MEMCACHE_HOST', None)
|
||||
if MEMCACHE_HOST == "none":
|
||||
MEMCACHE_HOST = None
|
||||
MEMCACHED_HOST_PATH = os.getenv('MEMCACHED_HOST_PATH', None)
|
||||
if MEMCACHED_HOST_PATH == "none":
|
||||
MEMCACHED_HOST_PATH = None
|
||||
|
@@ -7,6 +7,7 @@ handlers:
|
||||
console:
|
||||
class: rich.logging.RichHandler
|
||||
formatter: simple
|
||||
width: 255
|
||||
# access:
|
||||
# class: logging.FileHandler
|
||||
# filename: logs/access.log
|
||||
|
@@ -8,11 +8,19 @@ class DummyClient:
|
||||
def set(self, key, value, **kwargs):
|
||||
self._data[key] = value
|
||||
|
||||
def set_many(self, data, **kwargs):
|
||||
self._data.update(data)
|
||||
|
||||
def get(self, key, **kwargs):
|
||||
return self._data[key]
|
||||
|
||||
|
||||
if constants.MEMCACHE_HOST is None:
|
||||
if constants.MEMCACHED_HOST_PATH is None:
|
||||
client = DummyClient()
|
||||
else:
|
||||
client = Client(constants.MEMCACHE_HOST, timeout=1)
|
||||
client = Client(
|
||||
constants.MEMCACHED_HOST_PATH,
|
||||
timeout=1,
|
||||
allow_unicode_keys=True,
|
||||
encoding='utf-8'
|
||||
)
|
||||
|
@@ -1,6 +1,6 @@
|
||||
from pydantic import BaseModel, Field
|
||||
from pymemcache.client.base import Client
|
||||
|
||||
from .landmark import Landmark
|
||||
from .linked_landmarks import LinkedLandmarks
|
||||
import uuid
|
||||
|
||||
@@ -11,7 +11,7 @@ class Trip(BaseModel):
|
||||
|
||||
|
||||
@classmethod
|
||||
def from_linked_landmarks(self, landmarks: LinkedLandmarks, cache_client) -> "Trip":
|
||||
def from_linked_landmarks(self, landmarks: LinkedLandmarks, cache_client: Client) -> "Trip":
|
||||
"""
|
||||
Initialize a new Trip object and ensure it is stored in the cache.
|
||||
"""
|
||||
@@ -22,7 +22,9 @@ class Trip(BaseModel):
|
||||
|
||||
# Store the trip in the cache
|
||||
cache_client.set(f"trip_{trip.uuid}", trip)
|
||||
for landmark in landmarks:
|
||||
cache_client.set(f"landmark_{landmark.uuid}", landmark)
|
||||
cache_client.set_many({f"landmark_{landmark.uuid}": landmark for landmark in landmarks}, expire=3600)
|
||||
# is equivalent to:
|
||||
# for landmark in landmarks:
|
||||
# cache_client.set(f"landmark_{landmark.uuid}", landmark, expire=3600)
|
||||
|
||||
return trip
|
Reference in New Issue
Block a user