From 9718fc35ac90640f9ff1324af077c99fe43c4900 Mon Sep 17 00:00:00 2001 From: Zachary Sloan Date: Wed, 26 Jun 2013 21:48:44 +0000 Subject: Moved code creating DataSets object to a function in dataset.py Added caching to creating DataSets object --- wqflask/base/data_set.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'wqflask/base') 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)) -- cgit v1.2.3