Skip to content

Use Python's LRU cache instead of custom cache implementation #34

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

ralittles
Copy link

Switched over to using Python's built-in LRU cache functions for memoization

@ralittles
Copy link
Author

Unit test results:

 ◰³ venv  ~/mike_alexander_gitlab/Version1fromGithub/VersionOne.SDK.Python   use-lru-cache-instead-of-custom-cache *…  python setup.py test   Thu 13 Dec 2018 02:50:14 PM PST
running test
running egg_info
writing top-level names to v1pysdk.egg-info/top_level.txt
writing requirements to v1pysdk.egg-info/requires.txt
writing dependency_links to v1pysdk.egg-info/dependency_links.txt
writing v1pysdk.egg-info/PKG-INFO
reading manifest file 'v1pysdk.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
warning: no files found matching 'product.json'
writing manifest file 'v1pysdk.egg-info/SOURCES.txt'
running build_ext
test_create_story (tests.creation_tests.TestV1Create)
tests.creation_tests.TestV1Create.test_create_story ... ok
test_connect (tests.connect_tests.TestV1Connection)
tests.connect_tests.TestV1Connection.test_connect ... ok
test_connect_fails_when_invalid (tests.connect_tests.TestV1Connection)
tests.connect_tests.TestV1Connection.test_connect_fails_when_invalid ... ok
test_meta_connect_instance_and_address (tests.connect_tests.TestV1Connection)
tests.connect_tests.TestV1Connection.test_meta_connect_instance_and_address ... ok
test_meta_connect_instance_url (tests.connect_tests.TestV1Connection)
tests.connect_tests.TestV1Connection.test_meta_connect_instance_url ... ok
test_meta_connect_instance_url_overrides_separate (tests.connect_tests.TestV1Connection)
tests.connect_tests.TestV1Connection.test_meta_connect_instance_url_overrides_separate ... ok
test_meta_connect_oauth (tests.connect_tests.TestV1Connection)
tests.connect_tests.TestV1Connection.test_meta_connect_oauth ... ok
test_meta_connect_oauth_ignores_username (tests.connect_tests.TestV1Connection)
tests.connect_tests.TestV1Connection.test_meta_connect_oauth_ignores_username ... ok
test_reconnect_fails_when_invalid (tests.connect_tests.TestV1Connection)
tests.connect_tests.TestV1Connection.test_reconnect_fails_when_invalid ... ok
test_reconnect_succeeds_after_invalid (tests.connect_tests.TestV1Connection)
tests.connect_tests.TestV1Connection.test_reconnect_succeeds_after_invalid ... ok
test_find_query (tests.query_tests.TestV1Query)
tests.query_tests.TestV1Query.test_find_query ... ok
test_non_default_query (tests.query_tests.TestV1Query)
tests.query_tests.TestV1Query.test_non_default_query ... ok
test_select_epic (tests.query_tests.TestV1Query)
tests.query_tests.TestV1Query.test_select_epic ... ok
test_select_scope (tests.query_tests.TestV1Query)
tests.query_tests.TestV1Query.test_select_scope ... ok
test_select_story (tests.query_tests.TestV1Query)
tests.query_tests.TestV1Query.test_select_story ... ok
test_select_story_as_generic_asset (tests.query_tests.TestV1Query)
tests.query_tests.TestV1Query.test_select_story_as_generic_asset ... ok
test_select_task (tests.query_tests.TestV1Query)
tests.query_tests.TestV1Query.test_select_task ... ok
test_sum_query (tests.query_tests.TestV1Query)
tests.query_tests.TestV1Query.test_sum_query ... ok
test_split_attribute (tests.string_utils_tests.TestStringUtils)
tests.string_utils_tests.TestStringUtils.test_split_attribute ... ok
test_quick_close_and_reopen (tests.operation_tests.TestV1Operations)
tests.operation_tests.TestV1Operations.test_quick_close_and_reopen ... ok

----------------------------------------------------------------------
Ran 20 tests in 57.362s

OK
 ◰³ venv  ~/mike_a

@mtalexan
Copy link
Owner

@ralittles Does this work under Python 2.7 as well as Python 3.x?

@ralittles
Copy link
Author

@mtalexan No, the lru_cache function is only available in the Python 3 version of functools.

I tried to use the Python 2 repoze.lru library as instructed here (https://stackoverflow.com/questions/11815873/memoization-library-for-python-2-7), but the syntax was too different to use it as a drop-in replacement (at least when handling the clear cache part -- see here: http://docs.repoze.org/lru/narr.html#cleaning-cache-of-decorated-function).

Do you think we could drop support for Python 2 at this point? Otherwise the code is going to require several if/else statements for version checks to make sure the right syntax gets processed.

…al caching decorator in place but still need to figure out a nice way to use a different cache_clear() function depending on if its python2 or python3. Also, changed setup.py to allow installation of unittest dependencies as part of the regular install target, so that you don't have to download additional packages when you run unit tests. Also deleted the original handwritten cache-decorator implementation
@mtalexan mtalexan added the python3-only Change/feature can only be supported after Python2 support is dropped label Dec 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
python3-only Change/feature can only be supported after Python2 support is dropped
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants