-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#209: Add comments and move code to a more logical location
- Loading branch information
1 parent
74f1edd
commit 416288c
Showing
3 changed files
with
51 additions
and
22 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
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
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,29 @@ | ||
import logging | ||
|
||
from cachetools.lru import LRUCache | ||
|
||
log = logging.getLogger() | ||
|
||
|
||
class ExtendedLRUCache(LRUCache): | ||
""" | ||
An extension to cachetools' LRUCache class to allow client objects to be pushed back | ||
into the pool | ||
This version of LRU cache was chosen instead of the builtin LRU cache as it allows | ||
for addtional actions to be added when an item leaves the cache (controlled by | ||
`popitem()`). Since the builtin version was just a function (using a couple of | ||
wrapper functions), adding additional functionality wasn't possible. | ||
""" | ||
|
||
def __init__(self): | ||
super().__init__(maxsize=8) | ||
|
||
def popitem(self): | ||
key, client = super().popitem() | ||
session_id, client_pool = key | ||
log.debug(f"Item popped from LRU cache: {key}, {client}") | ||
# TODO - Session ID should probably get flushed here? | ||
# Put client back into pool | ||
# Passes in default stats for now, though these aren't used in the API | ||
client_pool._queue_resource(client, client_pool._get_default_stats()) |