diff options
-rwxr-xr-x | wqflask/base/data_set.py | 17 | ||||
-rw-r--r-- | wqflask/wqflask/views.py | 17 |
2 files changed, 30 insertions, 4 deletions
diff --git a/wqflask/base/data_set.py b/wqflask/base/data_set.py index e4bdb5c3..803cbc4f 100755 --- a/wqflask/base/data_set.py +++ b/wqflask/base/data_set.py @@ -27,8 +27,12 @@ import string import collections import json +import cPickle as pickle import itertools +from redis import Redis +Redis = Redis() + from flask import Flask, g import reaper @@ -70,6 +74,19 @@ def create_dataset(dataset_name, dataset_type = None): dataset_class = globals()[dataset_ob] return dataset_class(dataset_name) +def create_datasets_list(): + key = "all_datasets" + result = Redis.get(key) + if result: + print("Cache hit!!!") + result = pickle.loads(result) + else: + with Bench("Creating DataSets object"): + ds = DataSets() + Redis.set(key, pickle.dumps(result)) + Redis.expire(key, 2*60) + + def create_in_clause(items): """Create an in clause for mysql""" in_clause = ', '.join("'{}'".format(x) for x in mescape(*items)) diff --git a/wqflask/wqflask/views.py b/wqflask/wqflask/views.py index e48506ab..603ff49b 100644 --- a/wqflask/wqflask/views.py +++ b/wqflask/wqflask/views.py @@ -27,7 +27,7 @@ from flask import render_template, request, make_response, Response, Flask, g, c from wqflask import search_results from base.data_set import DataSet # Used by YAML in marker_regression -from base.data_set import DataSets +from base.data_set import create_datasets_list from wqflask.show_trait import show_trait from wqflask.show_trait import export_trait_data from wqflask.marker_regression import marker_regression @@ -54,9 +54,18 @@ def connect_db(): @app.route("/") def index_page(): print("Sending index_page") - with Bench("Creating DataSets object"): - ds = DataSets() - print("[orange] ds:", ds.datasets) + create_datasets_list() + #key = "all_datasets" + #result = Redis.get(key) + #if result: + # print("Cache hit!!!") + # result = pickle.loads(result) + #else: + # with Bench("Creating DataSets object"): + # ds = DataSets() + # Redis.set(key, pickle.dumps(result)) + # Redis.expire(key, 2*60) + #print("[orange] ds:", ds.datasets) return render_template("index_page.html") @app.route("/data_sharing") |