forked from tehkillerbee/mopidy-tidal
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
84a4c3e
commit 0edff26
Showing
14 changed files
with
995 additions
and
1,396 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from functools import wraps | ||
from cachetools import LRUCache, cached | ||
from cachetools.keys import hashkey | ||
|
||
|
||
_by_uri_cache = LRUCache(maxsize=16*1024) | ||
_items_cache = LRUCache(maxsize=16*1024) | ||
_futures_cache = LRUCache(maxsize=16*1024) | ||
|
||
cached_by_uri = cached( | ||
_by_uri_cache, | ||
key=lambda *args, uri, **kwargs: hash(uri), | ||
) | ||
cached_items = cached( | ||
_items_cache, | ||
key=lambda item, *args, **kwargs: hashkey(item.uri, item.last_modified), | ||
) | ||
cached_future = cached( | ||
_futures_cache, | ||
key=lambda *args, uri, **kwargs: hash(uri), | ||
) | ||
|
||
|
||
def cache_by_uri(_callable): | ||
@wraps(_callable) | ||
def wrapper(*args, **kwargs): | ||
item = _callable(*args, **kwargs) | ||
_by_uri_cache[hash(item.ref.uri)] = item | ||
return item | ||
return wrapper | ||
|
||
|
||
def cache_future(_callable): | ||
@wraps(_callable) | ||
def wrapper(*args, **kwargs): | ||
item = _callable(*args, **kwargs) | ||
if item: | ||
_futures_cache[hash(item.ref.uri)] = item | ||
return item | ||
return wrapper |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.