Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not cache empty responses #23

Merged
merged 1 commit into from
Feb 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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