Explore
Explore snippets
Discover reusable code snippets, examples, fixes, and ideas shared by developers, students, and teams.
Public snippets by CodShot user
1 public snippets
Python
Public
Fork: Async LRU Cache with TTL and Eviction Callback
Implements an asynchronous Least Recently Used (LRU) cache with a fixed size, optional time-to-live (TTL) for entries, background expiration...
Python
Preview
import asyncio
import time
from collections import OrderedDict
class AsyncLRUCache:
def __init__(self, maxsize):
self.maxsize = maxsize
self.cache = OrderedDict() # key -> (value, expire_time)
self.lock = asyncio.Lock()