forked from sun-guannan/VectCutAPI
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdraft_cache.py
More file actions
Latest commit
19 lines (17 loc) · 827 Bytes
/
Copy pathdraft_cache.py
File metadata and controls
19 lines (17 loc) · 827 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
fromcollectionsimportOrderedDict
importpyJianYingDraftasdraft
fromtypingimportDict
# Modify global variable, use OrderedDict to implement LRU cache, limit the maximum number to 10000
DRAFT_CACHE: Dict[str, 'draft.Script_file'] =OrderedDict() # Use Dict for type hinting
MAX_CACHE_SIZE=10000
defupdate_cache(key: str, value: draft.Script_file) ->None:
"""Update LRU cache"""
ifkeyinDRAFT_CACHE:
# If the key exists, delete the old item
DRAFT_CACHE.pop(key)
eliflen(DRAFT_CACHE) >=MAX_CACHE_SIZE:
print(f"{key}, Cache is full, deleting the least recently used item")
# If the cache is full, delete the least recently used item (the first item)
DRAFT_CACHE.popitem(last=False)
# Add new item to the end (most recently used)
DRAFT_CACHE[key] =value