def test_cache_singleton(self):
        a = ResultsCache.instance()
        params = {'query': 'hello'}
        output = {'movies': [1, 2]}
        a.store(params, output)

        b = ResultsCache.instance()
        cache_output = b.get(params)
        self.assertDictEqual(cache_output, output)
 def test_same_semantics(self):
     c = ResultsCache.instance()
     params1 = {'keywords': 'eScApe, pRiSoN'}
     params2 = {'keywords': 'prison,escape'}
     output1 = {'movies': [1, 2]}
     output2 = {'movies': [3, 4]}
     c.store(params1, output1)
     c.store(params2, output2)
     self.assertEqual(c.get(params1), c.get(params2))
 def test_cache_hashing(self):
     # Hash of 2 different query_params should be different
     c = ResultsCache.instance()
     params1 = {'query': 'hello'}
     params2 = {'query': 'world'}
     output1 = {'movies': [1, 2]}
     output2 = {'movies': [3, 4]}
     c.store(params1, output1)
     c.store(params2, output2)
     output1 = c.get(params1)
     self.assertTrue(output1)
     output2 = c.get(params2)
     self.assertTrue(output2)
     self.assertNotEqual(output1, output2,
                         'Outputs from different keys should be different')
 def test_multi_cache(self):
     c = ResultsCache.instance()
     c1 = 'Name One'
     c2 = 'Name Two'
     params1 = {'query': 'hello'}
     params2 = {'query': 'world'}
     output1 = {'movies': [1, 2]}
     output2 = {'movies': [3, 4]}
     c.store(params1, output1, c1)
     c.store(params2, output2, c2)
     self.assertFalse(c.get(params1, c2),
                      'Params 1 should not be in Cache 2')
     self.assertFalse(c.get(params2, c1),
                      'Params 2 should not be in Cache 1')
     self.assertEqual(c.get(params1, c1), output1)
     self.assertEqual(c.get(params2, c2), output2)
 def setUp(self) -> None:
     # Clear the cache
     c = ResultsCache.instance()
     c.clear_all()
 def test_cache_no_hit(self):
     c = ResultsCache.instance()
     c.store({'query': 'world'}, {'movies': [3, 4]})
     missing_output = c.get({'query': 'hello'})
     self.assertFalse(missing_output,
                      'If no hit, cache.get(key) should return False')
Esempio n. 7
0
from ir_eval.preprocessing import preprocess
from api.utils.cache import ResultsCache
from query_completion.model import predict_next_word

app = Flask(__name__)
CORS(app)

SWAGGER_URL = '/api/docs'
API_URL = '/static/swagger.json'

swaggerui_blueprint = get_swaggerui_blueprint(
    SWAGGER_URL, API_URL, config={'app_name': "TTDS Movie Search"})
app.register_blueprint(swaggerui_blueprint, url_prefix=SWAGGER_URL)

db = get_db_instance()
cache = ResultsCache.instance(
)  # Usage: cache.get(params, which_cache), cache.store(params, output, which_cache)
QUOTES_CACHE = 'quotes'
MOVIES_CACHE = 'movies'


@app.route('/')
def home():
    return 'Hello, World!'


def merge_lists(l1, l2, key):
    """ Updates one list with the matching information of the other, using the 'key' parameter.
        Input:
            l1, list to be updated
            l2, list with additional information
            key, matching key between two lists