Skip to content

Disable LRU 0.43.0 #767

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
12 changes: 6 additions & 6 deletions datadog/util/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,12 @@ def conditional_lru_cache(func):
the version of Python can support it (>3.2) and otherwise returns
the original function
"""
if not is_higher_py32():
return func
# if not is_higher_py32():
return func

log.debug("Enabling LRU cache for function %s", func.__name__)
# log.debug("Enabling LRU cache for function %s", func.__name__)

# pylint: disable=import-outside-toplevel
from functools import lru_cache
# # pylint: disable=import-outside-toplevel
# from functools import lru_cache

return lru_cache(maxsize=512)(func)
# return lru_cache(maxsize=512)(func)
100 changes: 50 additions & 50 deletions tests/unit/util/test_compat.py
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
# coding: utf8
# Unless explicitly stated otherwise all files in this repository are licensed under the BSD-3-Clause License.
# This product includes software developed at Datadog (https://www.datadoghq.com/).
# Copyright 2015-Present Datadog, Inc
import logging
import unittest

from mock import patch

from datadog.util.compat import conditional_lru_cache, is_higher_py32

class TestConditionalLRUCache(unittest.TestCase):
def test_normal_usage(self):
@conditional_lru_cache
def test_function(some_string, num1, num2, num3):
return (some_string, num1 + num2 + num3)

for idx in range(600):
self.assertEqual(
test_function("abc", idx, idx*2, idx *3),
("abc", idx + idx * 2 + idx *3),
)

def test_var_args(self):
@conditional_lru_cache
def test_function(*args):
return sum(list(args))

args = []
for idx in range(100):
args.append(idx)
self.assertEqual(
test_function(*args),
sum(args),
)

# pylint: disable=no-self-use
def test_debug_log(self):
test_object_logger = logging.getLogger('datadog.util')
with patch.object(test_object_logger, 'debug') as mock_debug:
@conditional_lru_cache
def test_function():
pass

test_function()

if is_higher_py32():
mock_debug.assert_called_once()
else:
mock_debug.assert_not_called()
# # coding: utf8
# # Unless explicitly stated otherwise all files in this repository are licensed under the BSD-3-Clause License.
# # This product includes software developed at Datadog (https://www.datadoghq.com/).
# # Copyright 2015-Present Datadog, Inc
# import logging
# import unittest

# from mock import patch

# from datadog.util.compat import conditional_lru_cache, is_higher_py32

# class TestConditionalLRUCache(unittest.TestCase):
# def test_normal_usage(self):
# @conditional_lru_cache
# def test_function(some_string, num1, num2, num3):
# return (some_string, num1 + num2 + num3)

# for idx in range(600):
# self.assertEqual(
# test_function("abc", idx, idx*2, idx *3),
# ("abc", idx + idx * 2 + idx *3),
# )

# def test_var_args(self):
# @conditional_lru_cache
# def test_function(*args):
# return sum(list(args))

# args = []
# for idx in range(100):
# args.append(idx)
# self.assertEqual(
# test_function(*args),
# sum(args),
# )

# # pylint: disable=no-self-use
# def test_debug_log(self):
# test_object_logger = logging.getLogger('datadog.util')
# with patch.object(test_object_logger, 'debug') as mock_debug:
# @conditional_lru_cache
# def test_function():
# pass

# test_function()

# if is_higher_py32():
# mock_debug.assert_called_once()
# else:
# mock_debug.assert_not_called()