Skip to content

Commit

Permalink
Add TTLCache for ListVCs (#619)
Browse files Browse the repository at this point in the history
  • Loading branch information
Anbang-Hu authored Nov 2, 2019
1 parent 86b5535 commit 194a12c
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/ClusterManager/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ kubernetes==10.0.0
PyYAML>=5.1.1
prometheus-client==0.7.1
twisted==19.2.1
cachetools==3.1.1
2 changes: 2 additions & 0 deletions src/RestAPI/dlwsrestapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -1225,6 +1225,7 @@ def endpoint_exist(endpoint_id):
data_handler = DataHandler()
for [_, endpoint] in endpoints.items():
data_handler.UpdateEndpoint(endpoint)
data_handler.Close()

resp = jsonify(endpoints)
resp.headers["Access-Control-Allow-Origin"] = "*"
Expand Down Expand Up @@ -1290,6 +1291,7 @@ def post(self):
dataHandler = DataHandler()
ret = {}
ret["result"] = dataHandler.UpdateTemplate(templateName, scope, json.dumps(template_json))
dataHandler.Close()
resp = jsonify(ret)
resp.headers["Access-Control-Allow-Origin"] = "*"
resp.headers["dataType"] = "json"
Expand Down
2 changes: 2 additions & 0 deletions src/utils/JobRestAPIUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import copy
import logging
from cachetools import cached, TTLCache


DEFAULT_JOB_PRIORITY = 100
Expand Down Expand Up @@ -531,6 +532,7 @@ def AddVC(userName, vcName, quota, metadata):
return ret


@cached(cache=TTLCache(maxsize=81920, ttl=300))

This comment has been minimized.

Copy link
@Anbang-Hu

Anbang-Hu Nov 2, 2019

Author Collaborator

Either the usage or package is problematic. Need further investigation.

def ListVCs(userName):
ret = []
vcList = DataManager.ListVCs()
Expand Down
1 change: 1 addition & 0 deletions src/utils/authorization.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def enum(*sequential, **named):
DEFAULT_EXPIRATION = 5 * 60


# TODO: Replace with TTLCache in cachetools after refactoring
class SimpleCache(object):
def __init__(self, expiration=DEFAULT_EXPIRATION):
self.expiration = expiration
Expand Down

0 comments on commit 194a12c

Please sign in to comment.