runtime
356 / 500
question 356 Memory & Python Internals · medium

Fix the recent-orders cache that keeps old orders

A support screen keeps only the most recent limit orders in memory. Memory keeps growing, and agents report that the order they just opened is often missing while week-old ones are still there. Find the bug in put and fix it, so the cache holds the newest limit orders and lets the oldest ones be freed.

ClassRecentOrders(limit) with put(order_id, order) and an orders dictionary
putstore the order; if more than limit are stored, remove the oldest one (the one added first)
Ruleadding an ID that is already stored replaces its order and counts it as newest

Loading your progress…

Fix the recent-orders cache that keeps old orders — Python practice · Runtime