Skip to content

Commit

Permalink
Do not cache empty responses
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan authored and pkittenis committed Feb 2, 2017
1 parent 6bfa4c0 commit e342bd7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
3 changes: 2 additions & 1 deletion influxgraph/classes/finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 10 additions & 1 deletion tests/test_influxdb_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit e342bd7

Please sign in to comment.