Skip to content

Commit

Permalink
store cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Nate-Wessel committed Dec 17, 2024
1 parent 6f19b4a commit 0e151c0
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion backend/app/get_travel_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import math
import pandas
import random
import json
from app.getGitHash import getGitHash

# the way we currently do it
Expand Down Expand Up @@ -35,7 +36,14 @@ def checkCache(uri):
return record # there could only be one

def cacheAndReturn(obj,uri):
# TODO: cache!
query = f'''
INSERT INTO nwessel.cached_travel_times (uri_string, commit_hash, results)
VALUES (%(uri)s, %(hash)s, %(results)s)
'''
connection = getConnection()
with connection:
with connection.cursor() as cursor:
cursor.execute(query, {'uri': uri, 'hash': getGitHash(), 'results': json.dumps(obj)})
return obj

def get_travel_time(start_node, end_node, start_time, end_time, start_date, end_date, include_holidays, dow_list):
Expand Down

0 comments on commit 0e151c0

Please sign in to comment.