← 返回题库
中级

实现设备状态Cache-Aside

未完成
中级参考 代码结构已给出,请填写 ____ 处
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(____))
    reads = cache[cache['____']=='____']
    total_reads = len(____)
    hits = int(reads['____'].sum())
    hit_rate = hits/total_reads if total_reads > ____ else ____
    print("____" + str(____))
    print("____" + str(____) + "____" + str(round(____)) + "____")
    print("____" + str(____))
    print(____)
    for _, row in reads.head(____).iterrows():
        action = "____" if row['____'] else "____"
        print(____)

示例

输入
solve()
期望输出
Cache reads: 16
Hits: 12 (75.0%)
Misses: 4
Cache-Aside pattern:
  device:DEV001:latest: HIT -> return cached
  device:DEV010:latest: HIT -> return cached
  device:DEV010:latest: HIT -> return cached
  device:DEV007:latest: MISS -> query DB -> write cache
  device:DEV001:latest: HIT -> return cached
Python 代码 🔒 登录后使用
🔒

登录后即可练习

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