예제 #1
0
    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)
예제 #2
0
    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)
예제 #3
0
 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'))
예제 #4
0
    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)
예제 #5
0
 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
예제 #6
0
 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
예제 #7
0
 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'))
예제 #8
0
 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"))