From e342bd79541536352446a0613acc2d47b976b705 Mon Sep 17 00:00:00 2001 From: Dan <22e889d8@opayq.com> Date: Thu, 2 Feb 2017 14:18:19 +0000 Subject: [PATCH] Do not cache empty responses --- influxgraph/classes/finder.py | 3 ++- tests/test_influxdb_integration.py | 11 ++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/influxgraph/classes/finder.py b/influxgraph/classes/finder.py index 943233a..f8e2321 100644 --- a/influxgraph/classes/finder.py +++ b/influxgraph/classes/finder.py @@ -481,7 +481,8 @@ def fetch_multi(self, nodes, start_time, end_time): logger.error("Type error generating query statement - %s", ex) return self._make_empty_multi_fetch_result(time_info, paths) data = self._run_infl_query(query, paths, measurement_data) - if self.memcache: + # Do not cache empty responses + if self.memcache and sum([len(vals) for vals in data.values()]) > 0: self.memcache.set(memcache_key, data, time=interval, min_compress_len=50) diff --git a/tests/test_influxdb_integration.py b/tests/test_influxdb_integration.py index 8c3f331..acc1a99 100644 --- a/tests/test_influxdb_integration.py +++ b/tests/test_influxdb_integration.py @@ -576,7 +576,16 @@ def test_memcache_integration(self): self.assertEqual(len(data[self.series1]), len(reader_data), msg="Reader cached data does not match finder cached data" " for series %s" % (self.series1,)) - + fake_nodes = [influxgraph.classes.leaf.InfluxDBLeafNode('fake.node', finder.reader)] + fake_nodes_memcache_key = influxgraph.utils.gen_memcache_key( + int(self.start_time.strftime("%s")), int(self.end_time.strftime("%s")), + aggregation_func, [n.path for n in fake_nodes]) + time_info, data = finder.fetch_multi( + fake_nodes, int(self.start_time.strftime("%s")), + int(self.end_time.strftime("%s"))) + self.assertTrue(fake_nodes[0].path in data) + self.assertFalse(finder.memcache.get(fake_nodes_memcache_key)) + def test_reader_memcache_integration(self): reader = influxgraph.InfluxDBReader(InfluxDBClient( database=self.db_name), self.series1, influxgraph.utils.NullStatsd(),