← 返回题库
中级

实现TTL缓存过期管理

未完成
中级参考 代码结构已给出,请填写 ____ 处
def solve():
    from pyodide.http import open_url
    from io import StringIO
    import pandas as pd
    cache_csv = open_url(____).read()
    cache = pd.read_csv(StringIO(____))
    writes = cache[cache['____']=='____']
    expires = cache[cache['____']=='____']
    print("____" + str(len(____)))
    print("____" + str(len(____)))
    ttl_dist = cache[cache['____']=='____']['____'].value_counts().to_dict()
    print("____" + str(____))
    active_cache = {}
    for _, row in cache.sort_values(____).iterrows():
        if row['____'] == '____':
            active_cache[row['____']] = {'____': ____, '____': row['____'] + row['____']}
        elif row['____'] in (____):
            active_cache.pop(____)
    now = cache['____'].max()
    still_alive = {k: v for k,v in active_cache.items() if v['____'] > now}
    print("____" + str(int(____)) + "____" + str(len(____)) + "____" + str(len(____)-len(____)))

示例

输入
solve()
期望输出
Writes: 9
Expires: 6
TTL distribution: {30: 9}
At t=1748736585: alive=1, expired=2
Python 代码 🔒 登录后使用
🔒

登录后即可练习

注册免费账号,在浏览器中直接运行 Python 代码