def test_cache_get(self): topic = self.create_topic() random_data = {'such': 'data'} topic_cache.set(topic, 'random_key', random_data, 3000) stored_data = topic_cache.get(topic, 'random_key') self.assertEqual(stored_data, random_data)
def test_cache_get(self): topic = self.create_topic() random_data = {"such": "data"} topic_cache.set(topic, "random_key", random_data, 3000) stored_data = topic_cache.get(topic, "random_key") self.assertEqual(stored_data, random_data)
def test_cache_delete(self): topic = self.create_topic() random_data = { 'such': 'data' } topic_cache.set(topic, 'such_random', random_data, 3000) topic_cache.delete(topic, 'such_random') self.assertIsNone(topic_cache.get(topic, 'such_random'))
def test_cache_get(self): topic = self.create_topic() random_data = { 'such': 'data' } topic_cache.set(topic, 'random_key', random_data, 3000) stored_data = topic_cache.get(topic, 'random_key') self.assertEqual(stored_data, random_data)
def get_most_related(self, rel): # Cache key to save the result of this function for each topic and rel cache_key = "most_related_%s" % rel # Get cache value most_related = topic_cache.get(self.topic, cache_key) # Return cache value if most_related is not None: return most_related # Build query query = """ START root=node(0) MATCH target-[r:`%s`]->(edge)<-[`<<INSTANCE>>`]-(type)<-[`<<TYPE>>`]-(root) WHERE type.app_label = "%s" AND HAS(edge.name) RETURN COUNT(target) as cnt, ID(edge) as id, edge.name as name, type.model_name as model ORDER BY cnt DESC LIMIT 5 """ % ( rel, self.topic.app_label() ) # Get data from neo4j most_related = connection.cypher(query).to_dicts() # Cache and return result topic_cache.set(self.topic, cache_key, most_related) return most_related
def test_cache_delete(self): topic = self.create_topic() random_data = {'such': 'data'} topic_cache.set(topic, 'such_random', random_data, 3000) topic_cache.delete(topic, 'such_random') self.assertIsNone(topic_cache.get(topic, 'such_random'))
def test_cache_delete(self): topic = self.create_topic() random_data = {"such": "data"} topic_cache.set(topic, "such_random", random_data, 3000) topic_cache.delete(topic, "such_random") self.assertIsNone(topic_cache.get(topic, "such_random"))