mirror of
https://github.com/spotipy-dev/spotipy.git
synced 2026-04-27 00:25:54 +03:00
[PR #625] [MERGED] Create CacheHandler to abstract caching tokens #968
Labels
No labels
api-bug
bug
dependencies
documentation
duplicate
enhancement
external-ide
headless-mode
implicit-grant-flow
invalid
missing-endpoint
pr-welcome
private-api
pull-request
question
spotipy3
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/spotipy#968
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/spotipy-dev/spotipy/pull/625
Author: @tonyaajjackson
Created: 12/16/2020
Status: ✅ Merged
Merged: 12/21/2020
Merged by: @stephanebruckert
Base:
master← Head:master📝 Commits (9)
7afe673Refactor functions into static methods of AuthBase5a48891Create CacheHandler to abstract caching tokens0f201b6Merge branch 'master' of github.com:plamere/spotipyb824d6dFix cache_handler subclass check for Python 2a4ad2dbSplit assert message to fix line over max length9d8c455Split cache handlers into cache_handler.py58d46ebflake8 and autopep fixesdb17532Fix init to allow importing CacheHandler5a5970cflake8 fix📊 Changes
6 files changed (+243 additions, -205 deletions)
View changed files
📝
CHANGELOG.md(+2 -1)📝
spotipy/__init__.py(+1 -0)➕
spotipy/cache_handler.py(+84 -0)📝
spotipy/oauth2.py(+108 -179)📝
spotipy/util.py(+1 -1)📝
tests/unit/test_oauth.py(+47 -24)📄 Description
Contributing.md Checklist:
Change Description
Previous code only supported caching to and from json files in a given directory. In addition, the get_cached_token method mixed getting and getting the token in the same method.
This change creates a
CacheHandlerclass to abstract out the caching implementation and allow the user to cache tokens in any way they see fit. For example, the user could create aMongoCacheclass to store and retrieve tokens from a Mongo database and specify thatcache_handler=MongoCachewhen creating anauth_managerobject.cache_handleris added as an argument toSpotifyOAuth,SpotifyPKCE, andSpotifyImplicitGrant. Specifying acache_handlernow overrides any specification ofcache_pathand/orusername.To preserve backwards compatibility in handling cache files, a
CacheFileHandlerclass extendingCacheHandleris created that implements previous functionality in getting and saving to json files. If nocache_handleris specified, thecache_pathandusernamearguments are used to create an instance ofCacheFileHandler. It may be worth deprecating thecache_pathandusernamefields in favour of usingCacheFileHandlerto simplify the interface.Tests are also modified and extended to cover the new functionality. A sample
MemoryCacheCacheHandlerthat stores the cached token as a variable in memory is created to test getting and saving to a customCacheHandler.Minor refactoring of
is_token_expiredand_is_scope_subsetalso performed to make adding theCacheHandlerabstraction easier.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.